This code returns null when I call the function:
var username = user.Claims
.FirstOrDefault(x => x.Type == JwtRegisteredClaimNames.GivenName)
.Value;
return username;
The code returns the logged in user's name when I use this url instead of JwtRegisteredClaimNames.GivenName
:
var username = user.Claims
.FirstOrDefault(x => x.Type == ";)
.Value;
return username;
Is there any other way to make this code work than using this url ?
This code returns null when I call the function:
var username = user.Claims
.FirstOrDefault(x => x.Type == JwtRegisteredClaimNames.GivenName)
.Value;
return username;
The code returns the logged in user's name when I use this url instead of JwtRegisteredClaimNames.GivenName
:
var username = user.Claims
.FirstOrDefault(x => x.Type == "http://schemas.xmlsoap./ws/2005/05/identity/claims/givenname")
.Value;
return username;
Is there any other way to make this code work than using this url http://schemas.xmlsoap./ws/2005/05/identity/claims/givenname
?
1 Answer
Reset to default 1The string value of JwtRegisteredClaimNames.GivenName
is just "given_name".
You should use System.Security.Claims.ClaimTypes.GivenName
which is exactly "http://schemas.xmlsoap./ws/2005/05/identity/claims/givenname".
docs
using System.Security.Claims;
var username = user.Claims.FirstOrDefault(x => x.Type == ClaimTypes.GivenName).Value;
return username;
JwtRegisteredClaimNames.GivenName
? – Daniel A. White Commented Mar 3 at 18:33