question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NameClaimType Doesn't Seem like Validation in TokenValidationParameters

See original GitHub issue

Apparently one must configure where to get the user’s name claim from so that they can perform operations like var name = User.Identity.Name;

In the following Azure-Samples/active-directory-b2c-dotnet-webapp-and-webapi example, the value is configured via TokenValidationParameters.

That doesn’t feel right to me. It is not validating the name claim, it is telling it where to find it, no?

app.UseOpenIdConnectAuthentication(
	new OpenIdConnectAuthenticationOptions
	{
		// Generate the metadata address using the tenant and policy information
		MetadataAddress = String.Format(AadInstance, Tenant, DefaultPolicy),

		// These are standard OpenID Connect parameters, with values pulled from web.config
		ClientId = ClientId,
		RedirectUri = RedirectUri,
		PostLogoutRedirectUri = RedirectUri,

                ....

		// Specify the claims to validate
		TokenValidationParameters = new TokenValidationParameters
		{
			NameClaimType = "name"
		},
	}
);

nameClaimType

Sets the claim type that specifies the Name property. The claim type is used to search for a Claim in the collection of ClaimsIdentity objects returned by the ValidateToken method of this token handler. The value of the matching claim is then set as the name of the IIdentity generated from this token handler.


Reference: Azure AD B2C: User.Identity.Name is null, but User.Identity.m_instance_claims[9] has the name

Reference: https://github.com/aspnet/AspNetKatana/issues/186

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
brentschmaltzcommented, Apr 3, 2018

@spottedmahn we will ping you when we start the async work.

1reaction
brentschmaltzcommented, Apr 3, 2018

@spottedmahn I get your point. Controlling the result of ClaimsIdentity.Name is probably not what one thinks about when validating a token. It is a separate step, ClaimsConfigurationParameters (or something named like it) may be a good container for all the settings one may want to use. I’ll reopen for now, and let’s think about it. We want to get a release ready by mid april. So I don’t think it fits this release. A future release will have an async pattern and will require new apis. Passing in a context returning a result may naturally fit into that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NameClaimType Doesn't Seem like Validation in ...
Apparently one must configure where to get the user's name claim from so that they can perform operations like var name = User.Identity....
Read more >
I can Authenticate with my JWT but my Name claim is not ...
TokenValidationParameters = new TokenValidationParameters { NameClaimType = "name" }) . That'll change which claim it uses to populate the name.
Read more >
Debugging JwtBearer Claim Problems in ASP.NET Core
Its primary purpose is to look for an access token in the incoming request, and if one is found, validate it and create...
Read more >
TokenValidationParameters.NameClaimType Property
Controls the value Name returns. It will return the first Value where the Type equals NameClaimType. The default is DefaultNameClaimType.
Read more >
Why does my Authorize Attribute not work? - leastprivilege.com
In that case you need to be aware of the default behaviour of ClaimsPrincipal – and either set the NameClaimType and RoleClaimType to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found