Using ASP.NET Core 2.2 and Identity Server 4 I have the following controller:
[HttpGet("posts"), Authorize]
public async Task<IActionResult> GetPosts() {
var authenticated = this.User.Identity.IsAuthenticated;
var claims = this.User.Identities.FirstOrDefault().Claims;
var id = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
}
I get all the claims
but id
is null ...
I checked all values in claims
and I have a 'sub' claim with value 1.
Why is ClaimTypes.NameIdentifier not mapping to 'sub'?
sub
claim gets translated into thenameidentifier
claim. – Dewie