Repository navigation
Description
Description
In Blazor Server, MicrosoftIdentityConsentAndConditionalAccessHandler.User retains the circuit's initial principal after the application's AuthenticationStateProvider publishes an authentication-state change.
Blazor's cascading authentication state updates correctly, but the Microsoft.Identity.Web consent handler continues returning the original user. This can cause incremental-consent and conditional-access challenges to use stale user information.
Package: Microsoft.Identity.Web 4.15.0
Framework: .NET 10, Blazor Server
Reproduction
A complete, standalone reproduction is available at:
https://github.com/danroth27/IdentityWebBlazorAuthStateRepro
The app uses the published NuGet package and registers the real consent/circuit handler through AddMicrosoftIdentityConsentHandler(). No library internals are copied, mocked, or modified.
With the .NET 10 SDK installed:
git clone https://github.com/danroth27/IdentityWebBlazorAuthStateRepro.git
Set-Location .\IdentityWebBlazorAuthStateRepro
dotnet run --launch-profile httpOpen http://localhost:5011, then:
- Confirm both table rows initially show Alice, authenticated.
- Click Switch to Bob without reloading. Blazor's current user becomes Bob, but the consent handler still shows Alice.
- Click Become anonymous. Blazor's current user becomes anonymous and unauthenticated, but the consent handler still shows Alice, authenticated.
- Click Start a new circuit. Both rows reset to Alice.
Actual behavior
| Action | Blazor authentication state | Consent handler's user |
|---|---|---|
| Initial load | Alice, authenticated | Alice, authenticated |
| Switch to Bob | Bob, authenticated | Alice, authenticated |
| Become anonymous | Anonymous, unauthenticated | Alice, authenticated |
These results were reproduced in a browser using the published 4.15.0 package.
The buttons use synthetic, circuit-scoped identities and publish completed authentication-state tasks through NotifyAuthenticationStateChanged. They do not perform real sign-in or sign-out, acquire tokens, or require an Entra tenant. This isolates the state-synchronization problem; it does not demonstrate an authorization bypass.
Expected behavior
After an authentication-state change resolves successfully, the consent handler should reflect the current principal, including transitions to an anonymous user.
Relevant implementation
MicrosoftIdentityServiceHandler reads the authentication state when the circuit opens:
var state = await Provider.GetAuthenticationStateAsync().ConfigureAwait(false);
Service.User = state.User;It does not subscribe to AuthenticationStateProvider.AuthenticationStateChanged, so the stored principal is not refreshed.
Fix considerations
The fix should cover changes after initialization, changes during initialization, out-of-order task completion, failed or canceled state tasks, and subscription cleanup when the circuit closes.
Successful circuit initialization must establish a usable principal. A pending change notification must not cause the initial principal to be discarded while allowing initialization to finish with User unset. That separate race was identified in the unmerged implementation proposed in #4068, not in the published-package reproduction above.
This existing synchronization problem surfaced during the .NET 11 work in #4068 through analyzer BL0013. It should be addressed independently of the SDK, dependency, and target-framework changes.
Activity