Skip to content

feat(msal): cache the ID token so apps can read the user's claims - #3185

Merged
kazo0 merged 3 commits into
mainfrom
dev/sb/msal-claims
Sep 23, 2026
Merged

kazo0 merged 3 commits into
mainfrom
dev/sb/msal-claims

Conversation

@kazo0

@kazo0 kazo0 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

The MSAL provider only copied the access token into the Uno token cache, so ITokenCache.TokenAsync(IdTokenKey) was always empty while the OIDC provider populates it. A B2C app had no way to read the user's claims (custom attributes, roles, user flow) for in-app authorization.

  • store AuthenticationResult.IdToken under TokenCacheExtensions.IdTokenKey
  • Given_MsalAuthentication.When_Login_Then_IdTokenCached (red before, green after)
  • assert the ID token survives a silent refresh
  • When_TokenResponseHasNoAccessToken_Then_NotAuthenticated pins the B2C openid-only case
  • token-leak guard now also asserts the ID token never reaches the logs
  • docs: B2C authority/scope/broker/redirect notes and a "Reading the user's claims" section

The MSAL provider only copied the access token into the Uno token cache,
so ITokenCache.TokenAsync(IdTokenKey) was always empty while the OIDC
provider populates it. A B2C app had no way to read the user's claims
(custom attributes, roles, user flow) for in-app authorization.

- store AuthenticationResult.IdToken under TokenCacheExtensions.IdTokenKey
- Given_MsalAuthentication.When_Login_Then_IdTokenCached (red before, green after)
- assert the ID token survives a silent refresh
- When_TokenResponseHasNoAccessToken_Then_NotAuthenticated pins the B2C openid-only case
- token-leak guard now also asserts the ID token never reaches the logs
- docs: B2C authority/scope/broker/redirect notes and a "Reading the user's claims" section

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FmSTEgLz4csBxzrsYe7p8G
@mergify

mergify Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

kazo0 and others added 2 commits September 17, 2026 17:50
TokenCache.SaveAsync wrote keys in dictionary order with no failure
isolation. On packaged WinAppSDK (LocalSettings caps a value at 8 KB) a
claim-heavy ID token threw after the access token was written, so
LoginAsync / RefreshAsync threw while HasTokenAsync reported true.

- write the ID token last and best-effort; log key + length, never the value
- clear the in-memory remnant the caching stores write before the backing store
- a rejected access token still throws
- Given_TokenCache.When_IdTokenRejectedByStorage_Then_SessionKeptWithoutIt (red before, green after)
- Given_TokenCache.When_AccessTokenRejectedByStorage_Then_SaveThrows

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AYYN6BiumAAF6B4H6WhW4H
With only openid / offline_access scopes B2C returns an ID token and a
refresh token but no access token. The provider reported not signed in
yet left MSAL's account and refresh token cached - cleartext
localStorage on WebAssembly - logged nothing above Trace, and redeemed
that refresh token silently on every later sign-in before prompting.

- TokensOrSignOutAsync on login and refresh: Warning naming the scopes, then
  remove the MSAL accounts and serialized cache
- RemoveAccountsAsync extracted from logout and shared
- When_TokenResponseHasNoAccessToken_Then_NotAuthenticated asserts the warning,
  the removed cache entry and a single token request on the next sign-in
  (red before, green after on the desktop head)
- docs: correct the B2C scope note and the packaged-Windows 8 KB note
- specs/012: record both review-panel fixes and what is still open

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AYYN6BiumAAF6B4H6WhW4H
@kazo0

kazo0 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport servicing/7.4

@mergify

mergify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

backport servicing/7.4

✅ Backports have been created

Details

@kazo0
kazo0 merged commit 2dbbe73 into main Sep 23, 2026
27 of 28 checks passed
@kazo0
kazo0 deleted the dev/sb/msal-claims branch September 23, 2026 14:54
kazo0 added a commit that referenced this pull request Sep 23, 2026
…-3185

feat(msal): cache the ID token so apps can read the user's claims (backport #3185)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants