AzureAD / microsoft-authentication-library-for-js

Microsoft Authentication Library (MSAL) for JS
http://aka.ms/aadv2
MIT License
3.6k stars 2.64k forks source link

[chrome extension/service worker] Chrome.Storage cache location when using service workers. #3666

Open LoveSponge opened 3 years ago

LoveSponge commented 3 years ago

Core Library

MSAL.js v2 (@azure/msal-browser)

Wrapper Library

Not Applicable

Description

In order to make msal play nice with chrome extension in a service worker, the cache location can be 'mocked' by forcing window.localStorage to instead use chrome.storage apis. The problem is that these apis are asynchronous, and there is no way to make the cache location functions work nicely with asynchronous get/set/clear/etc...

Source

External (Customer)

jasonnutter commented 3 years ago

@LoveSponge We're aware of this limitation of the current storage options. We are looking into how to support async storage options (e.g. chrome.storage, IndexedDB, etc). For now, you may need to use the MSAL MemoryStorage option, and implement your own caching outside MSAL until we are able to provide built-in support for async storage interfaces.

LoveSponge commented 3 years ago

@jasonnutter Thanks for getting back to me.

That's great to know, maybe you could help me with my current issue - i've implemented my own 'localstorage' which basically just points each of the *Item functions to chrome.storage functions instead... (chrome.storage.sync.{get,set,remove}Item)

My issue is that it doesn't appear to be setting any values, only getting and removing them? i'm using an implementation that mimics the Chromium Extension Sample but with the aforementioned poxied localStorage object.

When I do the 'SignIn' through chrome.identity.launchWebAuthFlow(), I can't see that msal is actually setting any localstorage at all? What am I missing?

To be clear on this, the issue i believe this is causing is that no account is ever registered or any tokens set at all, causing the call to msalInstance.handleRedirectPromise(...) to always return null.

Thanks in advance, LS

Alino commented 2 years ago

...until we are able to provide built-in support for async storage interfaces.

Any ETA on this please?

Alino commented 2 years ago

relation with https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/5023

rendomnet commented 1 year ago

@jasonnutter Is there any proper solution or sample code for this issue?