Repository navigation
feat(msal): persist the token cache on WebAssembly through IKeyValueStorage - #3162
Merged
Merged
Conversation
4 of 7 tasks
kazo0
force-pushed
the
msal-3-wasm-token-cache
branch
from
August 25, 2026 01:17
ac7b819 to
f080636
Compare
kazo0
force-pushed
the
msal-3-wasm-token-cache
branch
2 times, most recently
from
August 25, 2026 01:32
e00dae1 to
a84a1f4
Compare
kazo0
force-pushed
the
msal-3-wasm-token-cache
branch
from
August 25, 2026 15:37
a84a1f4 to
2edb8c2
Compare
kazo0
force-pushed
the
msal-3-wasm-token-cache
branch
from
August 25, 2026 15:38
2edb8c2 to
4235ee3
Compare
rajamatt
approved these changes
Aug 25, 2026
ajpinedam
approved these changes
Aug 25, 2026
kazo0
force-pushed
the
msal-3-wasm-token-cache
branch
2 times, most recently
from
August 25, 2026 16:44
58aa847 to
8543148
Compare
Contributor
Author
|
/azp run |
|
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
…torage Layer 3/4 of the MSAL authentication work (#3139). Before this the MSAL cache was memory-only in the browser, so every page reload meant signing in again. - MsalCacheHelper has no browser backend, so on WebAssembly the provider registers SetBeforeAccessAsync/SetAfterAccessAsync callbacks that serialize the cache through MsalTokenCacheStore into the host's default IKeyValueStorage, keyed MsalCache_{ClientId}. Which store that is - and so whether the cache survives a reload or a tab close - is the storage layer's KeyValueStorageConfiguration:BrowserCacheLocation (localStorage by default); this side only reads and writes the blob, so MemoryStorage yields the old in-memory behavior for free - MsalKeyValueStorage wraps the resolved default store for injection, since a bare IKeyValueStorage registration resolves to the in-memory one - Sign-out and ITokenCache.Cleared both delete the serialized cache, in a finally and with CancellationToken.None, so a cancelled or failed sign-out cannot leave refresh-token material behind - A warning names the store whenever the cache is persisted unprotected: the serialized cache holds the refresh token, and only an Entra `spa` registration caps that token at 24 non-sliding hours Tests: Given_MsalTokenCacheStore (unit) covers the round trip, key layout, corrupt-blob handling and no-op writes; the UI suite gains the sign-out / cancelled sign-out / Cleared purge cases and the "persisted only on WebAssembly" guard, and the WebAssembly lane runs it. Docs: the browser cache section of the how-to (store choice, the `spa` prerequisite and why it matters) and the migration note. Spec 011 carries the design trail. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH
kazo0
force-pushed
the
msal-3-wasm-token-cache
branch
from
August 25, 2026 17:24
8543148 to
2a25f1c
Compare
|
Tick the box to add this pull request to the merge queue (same as
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub Issue (If applicable): closes #3158 (layer 3/4 of #3155; relates to #2438)
Stack 3/4 — base:
msal-2-runtime-dispatch. Review only this layer's diff. Depends on layer 2 for the provider's runtime dispatch (which decides where the browser branch runs) and on #3153 forIKeyValueStorageon WebAssembly (localStorage/sessionStoragebackends). Deliberately deferred upward: the Uno version floor (layer 4).PR Type
What is the current behavior?
On WebAssembly the MSAL token cache is memory-only:
MsalCacheHelperhas no browser backend, so the provider skips cache setup and every page reload — or a navigation away and back — means signing in again. Nothing removes cache material on sign-out because there is nothing persisted to remove.What is the new behavior?
The browser branch serializes the MSAL cache through
IKeyValueStorage. On WebAssembly the provider registersSetBeforeAccessAsync/SetAfterAccessAsynccallbacks that read and write the serialized cache (MsalTokenCacheStore, keyMsalCache_{ClientId}) into the host's default key-value store. Which store is the storage layer's decision —KeyValueStorageConfiguration:BrowserCacheLocation,localStorageby default — so a page reload keeps the session,sessionStoragescopes it to the tab, andMemoryStorageyields the previous in-memory behaviour for free.MsalKeyValueStoragewraps the resolved default store for injection, because a bareIKeyValueStorageregistration resolves to the in-memory one.Sign-out and
ITokenCache.Clearedboth delete the serialized cache — in afinally, withCancellationToken.None— so a cancelled or failed sign-out cannot leave refresh-token material in the browser.A warning names the store whenever the cache is persisted unprotected. The serialized cache holds the refresh token; only an Entra
spaplatform registration caps that token at 24 non-sliding hours, and the how-to now says so as a prerequisite.Tests.
Given_MsalTokenCacheStore(unit): round trip, key layout, corrupt-blob handling, no-op writes.Given_MsalAuthentication(UI, real MSAL againstStubEntra): sign-out purges the store, cancelled sign-out purges the store,Clearedpurges the store, and a guard that the cache is persisted only on WebAssembly.RuntimeTestsFilteralready covers the namespace, so the WebAssembly lane from layer 1 runs the new cases. Specspecs/011carries the design trail.Behaviour changes (documented in
UpdatingExtensions.md)WebAssembly sign-in state now survives a reload by default; apps that want the old memory-only behaviour set
BrowserCacheLocationtoMemoryStorage.PR Checklist
Other information
Verified locally: MSAL.Tests 39/39; package surface builds warning-free on all seven TFMs; desktop runtime suite 17 MSAL + 8 storage = 25/25. The persisted-cache path itself only executes on the WebAssembly lane (desktop asserts it stays off).
🤖 Generated with Claude Code
https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH