Repository navigation
fix(auth): stop logging tokens and fix the refresh, sign-out and provider-build paths - #3152
Merged
Merged
Conversation
…ider-build paths Provider-independent defects in Uno.Extensions.Authentication, none of them covered by a test until now. Split out of #3139 as its auth-core layer. - TokenCache logged every cached value at Trace when enumerating keys, and HeaderHandler logged the bearer at Debug on every outbound request - both to the consumer's configured logging pipeline (AGENTS.md section 7). They now log key + value length, and the scheme only - AuthenticationService.RefreshAsync saved whatever the provider returned; a provider returning nothing (expired or revoked refresh token) left no tokens but never raised ITokenCache.Cleared, so LoggedOut did not fire and an app that navigates on it sat on a signed-in page with nothing to send. It now clears the cache, the same as an explicit sign-out - LogoutAsync let a provider exception escape before _tokens.ClearAsync ran, so a sign-out that failed part-way (a locked keychain, a cache-file error) left the access token in place and IsAuthenticated true. It now clears with CancellationToken.None - a cancelled token must not skip it - and rethrows. A provider returning false is unchanged: that is "the sign-out did not happen", and the session stands - The provider table was populated behind a Count == 0 check and each provider configured with a bare ??=, so two concurrent callers could both build. ConfigureProvider returns a record copy, so the losing MSAL instance stayed subscribed to ITokenCache.Cleared with nothing left to unsubscribe it. Both are Lazy (ExecutionAndPublication) now; Providers still reports only what has been built, since reading a property must not construct a client application - The LoginAsync(CancellationToken) remarks now say the overload passes no IDispatcher New Uno.Extensions.Authentication.Tests (net9.0 MSTest, in the package-CI VSTest filter): 12 tests. Every fix was verified red first - the two log-leak guards fail against main's TokenCache and HeaderHandler, the refresh and sign-out cases against main's AuthenticationService. Verified: Authentication.Tests 12/12; Uno.Extensions-packageonly.slnf Release 0 errors, which covers the MSAL, OIDC and Authentication.WinUI consumers. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH
kazo0
enabled auto-merge
August 24, 2026 16:41
rajamatt
approved these changes
Aug 24, 2026
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): split out of #3139
PR Type
What is the current behavior?
Five defects in
Uno.Extensions.Authentication, all provider-independent, none covered by a test:TokenCacheprints every cached value at Trace when it enumerates keys, andHeaderHandlerlogs the bearer token at Debug on every outbound request. Both go to the consumer's configured logging pipeline (AGENTS.md §7 forbids exactly this).RefreshAsyncsaves whatever the provider returns; a provider that returns nothing (expired or revoked refresh token) leaves the cache with no tokens but never raisesITokenCache.Cleared, soLoggedOutis not raised and an app that navigates on it sits on a signed-in page with nothing to send.LogoutAsync(a locked keychain, a cache-file error), the exception escapes before_tokens.ClearAsyncruns: the access token survives,IsAuthenticatedstays true, and the HTTP handlers keep sending the bearer for a user who asked to sign out.AuthenticationServicepopulated its provider table behind aCount == 0check andProviderFactoryconfigured its provider with a bare??=; two concurrent callers - an HTTP handler refreshing while the UI asksIsAuthenticated, say - could both build.ConfigureProviderreturns a record copy, so the losing instance stayed alive, subscribed toITokenCache.Cleared, with nothing left to unsubscribe it.IAuthenticationService.LoginAsync(CancellationToken)'s docs did not say that it passes noIDispatcher, which some providers require.What is the new behavior?
TokenCachelogs key + value length;HeaderHandlerlogs the scheme only.RefreshAsyncclears the token cache when the provider returns no tokens, soClearedandLoggedOutfire - the same as an explicit sign-out. A provider that keeps its tokens on a transient failure is unaffected.LogoutAsyncclears the token cache (CancellationToken.None, so a cancelled token cannot skip it) and rethrows when the provider throws. A provider returningfalseis unchanged: that is "the sign-out did not happen", and the session stands.Lazy,ExecutionAndPublication).Providersstill reports only what has been built - reading a property must not construct MSAL's client application.LoginAsync(CancellationToken)remarks say what the overload cannot do.New
Uno.Extensions.Authentication.Tests(plainnet9.0MSTest, in the package-CI VSTest filter): 12 tests - refresh returns nothing / empty / tokens, logout throws / throws with a cancelled token / declines, concurrent calls build once,Providersdoes not build,ProviderFactoryconfigures once, and two log-leak guards. Every fix was verified red before it: the two leak guards fail againstmain'sTokenCacheandHeaderHandler, the refresh and logout cases againstmain'sAuthenticationService.PR Checklist
UpdatingExtensions.mdon feat(msal): platform-correct sign-in, token cache and sign-out, tested on four heads #3139, to land with the MSAL layer that depends on themLoggedOutnow fires in one more situation (an unrenewable session), which is the documented meaning of the eventOther information
Verified locally:
Uno.Extensions.Authentication.Tests12/12 (2/12 red withmain'sTokenCache+HeaderHandler);Uno.Extensions-packageonly.slnfRelease build 0 errors, which covers the MSAL, OIDC andAuthentication.WinUIconsumers of the changed internals.Reviewer note: this is the auth-core layer of #3139's split. The MSAL provider changes that build on it (
TokensOrNull, keeping tokens on transient refresh failures, sign-out removing every account) come in a later PR with their end-to-end tests; nothing here depends on them.🤖 Generated with Claude Code
https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH