I am using following line of code for getting claims from azure ad, but I am unable to get first and second/last name of user.
var handler = new JwtSecurityTokenHandler();
JwtSecurityToken decodedeIdtoken = handler.ReadToken(base64IDToken) as JwtSecurityToken;
var claims = decodedeIdtoken.Claims;
Also,I have configured given_name and family_name in token configuration of my application on azure portal.
Kindly suggest possible solution to get first and last name in JWT claim.
2
Answers
You need to be sure that the
Given name
andSurname
claims are returned as a part of the JWT token:If these are selected and the authenticated user has associated given name and surname values, the JWT token will include
given_name
andfamily_name
inside its payload.Moreover, if you need to, you can collect these attributes on sign up – the user will be required to enter values for his/her first and last name.
Then the signup form will look like this (note the
Given name
andSurname
inputs at the end):I registered one Azure AD application and added API permissions as below:
In Token configuration, I added both
family_name
andgiven_name
like below:Now I generated access token using authorization code flow via Postman with
scope
as below:Response:
When I decoded these tokens by pasting them in jwt.ms website, both have
given_name
andfamily_name
claims like below:ID Token:
Access token: