dotnet / dotnet/aspnetcore

Blazor AccountClaimsPrincipalFactory CreateUserAsync fires multiple times when refreshing the browser

Open
#46,060 15 comments 1 reaction 0 assignees View on GitHub
area-blazor bug feature-blazor-msal feature-blazor-wasm Pillar: Technical Debt Priority:2
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

I have a custom AccountClaimsPrincipalFactory in my Blazor WASM project that retrieves some information from the server to set some additional claims on the ClaimsPrincipal that gets created. When I log in, this factory's CreateUserAsync method fires just once which is good.

But if I refresh my browser window after having been signed in just by pressing F5, the logic in the AccountClaimsPrincipalFactory I have created fires three times.

I am using this in conjunction with Azure AD B2C with the MSAL Nuget package as per Microsoft documentation.

I have tried using the account parameter that gets passed in to retrieve the "nonce" from the AdditionalUserProperties property to compare the nonce being passed in on each execution of this method and it is the same every time.

Out of curiosity, is this method being fired for every token returned by Azure AD? When I log on, I receive an ID token, an Access token, and of course, a Refresh token. is there a correlation here or is that just a coincidence?

### Expected Behavior

This method should fire just once both when logging in and when refreshing the browser.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

7.0.101

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.