While reading the documentation for adding custom claims, I don’t understand what the use is of ‘always’ adding the identity.
Instead of the code sample provided
ClaimsIdentity claimsIdentity = new ClaimsIdentity();
var claimType = "myNewClaim";
if (!principal.HasClaim(claim => claim.Type == claimType))
{
claimsIdentity.AddClaim(new Claim(claimType, "myClaimValue"));
}
principal.AddIdentity(claimsIdentity);
return Task.FromResult(principal);
I was expecting something more along the lines of
var claimType = "myNewClaim";
if (!principal.HasClaim(claim => claim.Type == claimType))
{
ClaimsIdentity claimsIdentity = new ClaimsIdentity();
claimsIdentity.AddClaim(new Claim(claimType, "myClaimValue"));
principal.AddIdentity(claimsIdentity);
}
return Task.FromResult(principal);
Why add the identity if the principal already has the claim?
New contributor
Brecht Yperman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.