microsoft-authentication-library-for-js icon indicating copy to clipboard operation
microsoft-authentication-library-for-js copied to clipboard

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

Open LoveSponge opened this issue 4 years ago • 5 comments

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)

LoveSponge avatar May 21 '21 11:05 LoveSponge

@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.

jasonnutter avatar May 21 '21 15:05 jasonnutter

@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

LoveSponge avatar May 24 '21 09:05 LoveSponge

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

Any ETA on this please?

Alino avatar Jul 15 '22 22:07 Alino

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

Alino avatar Jul 19 '22 15:07 Alino

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

rendomnet avatar Jan 08 '23 05:01 rendomnet