Skip to content

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

Merged
kazo0 merged 3 commits into
servicing/7.4from
mergify/bp/servicing/7.4/pr-3185
Sep 23, 2026
Merged

kazo0 merged 3 commits into
servicing/7.4from
mergify/bp/servicing/7.4/pr-3185

Conversation

@mergify

@mergify mergify Bot commented Sep 23, 2026

Copy link
Copy Markdown

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

This is an automatic backport of pull request #3185 done by [Mergify](https://mergify.com).

kazo0 and others added 3 commits September 23, 2026 14:54
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
(cherry picked from commit c8f3019)
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
(cherry picked from commit 4de349b)
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
(cherry picked from commit d31e118)
@kazo0
kazo0 enabled auto-merge September 23, 2026 14:55
@kazo0
kazo0 merged commit ed20a49 into servicing/7.4 Sep 23, 2026
23 checks passed
@kazo0
kazo0 deleted the mergify/bp/servicing/7.4/pr-3185 branch September 23, 2026 15:27
ushenkodmitry pushed a commit to ushenkodmitry/Uno.Samples that referenced this pull request Nov 4, 2026
… sample

Uno.Extensions 7.4.0-dev.54 is the first build whose MSAL provider caches
the ID token next to the access token (unoplatform/uno.extensions#3188),
which is the only place an app can read the signed-in user's claims. Pin
it, and have the Sign in page's TOKEN card decode the ID token's payload
so the claims (name, preferred_username, oid, tid, ...) are visible
without leaving the app.

- MsalFlowService.DescribeClaimsAsync reads IdTokenKey from ITokenCache
  and decodes the payload to indented JSON; the existing token summary
  already lists the new IdToken entry with its length
- SignInViewModel.ClaimsSummary, hidden until a token is cached and
  scrubbed through SecretRedactor.ApplyToJson while recording
- README: TOKEN card description and the "what the provider does" list

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_015CwhNQC1BFcQiymU9GvsP1
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.

1 participant