Identity.Name is always null on the client: the access token names the user in unique_name, the client reads name

Open Beginner friendly
#15,051 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp

Research direction

Start at IAuthTokenProvider.ParseAccessToken, where the client's ClaimsPrincipal is built with nameType: "name", and compare it with the claim name the server writes (unique_name). Check ClaimsPrincipalExtensions.GetUserName() and AuthManager.KeepActiveAccount to see how the name is read. Done when Identity.Name is non-null for a signed-in user on the client, and the existing authentication tests still pass.

Written by the indexing model from the issue text.

Description

The server writes the access token with JwtSecurityTokenHandler, which writes ClaimTypes.Name under its short name unique_name (its DefaultOutboundClaimTypeMap). IAuthTokenProvider.ParseAccessToken builds the client's ClaimsPrincipal with nameType: "name", so on the client Identity.Name is null for every signed-in user.

The client's authentication state comes from that principal, so context.User.Identity.Name in an AuthorizeView and AuthenticationState.User.Identity.Name are null as well. In the template itself, AuthManager.KeepActiveAccount takes the kept account's UserName from it, so an account whose profile hasn't been loaded is kept with no user name. Most of the template doesn't notice, because ClaimsPrincipalExtensions.GetUserName() reads both ClaimTypes.Name and unique_name.

The parsed principal's name type should be the claim the server writes, so Identity.Name holds the user's name on the client as it does on the server.

Dominant language
C#
Stars
1.4k
Forks
264
Avg merge
8h 58m
Merged PRs (30d)
579

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bitfoundation/bitplatform

All issues in bitfoundation/bitplatform

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.