I'm integrating Google OAuth in my application. I was fetching name and email when I'm logging in, but when I login and try to fetch the gender and date of birth, it returned Null
.
This is my code for the FullName
and Email
:
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
var firstName = info.Principal.FindFirstValue(ClaimTypes.GivenName);
var lastName = info.Principal.FindFirstValue(ClaimTypes.Surname);
var fullName = $"{firstName} {lastName}";
That code returned all the data in my profile, I try to get the gender and date of birth in the same format, but it is not being fetched.
var gender = info.Principal.FindFirstValue(ClaimTypes.Gender);
var dateOfBirth = info.Principal.FindFirstValue(ClaimTypes.DateOfBirth);
I'm integrating Google OAuth in my application. I was fetching name and email when I'm logging in, but when I login and try to fetch the gender and date of birth, it returned Null
.
This is my code for the FullName
and Email
:
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
var firstName = info.Principal.FindFirstValue(ClaimTypes.GivenName);
var lastName = info.Principal.FindFirstValue(ClaimTypes.Surname);
var fullName = $"{firstName} {lastName}";
That code returned all the data in my profile, I try to get the gender and date of birth in the same format, but it is not being fetched.
var gender = info.Principal.FindFirstValue(ClaimTypes.Gender);
var dateOfBirth = info.Principal.FindFirstValue(ClaimTypes.DateOfBirth);
Share
Improve this question
edited Jan 20 at 5:52
marc_s
754k184 gold badges1.4k silver badges1.5k bronze badges
asked Jan 20 at 5:27
Christian MedalladaChristian Medallada
941 silver badge6 bronze badges
1
- How have you configured the necessary claimsmapping? see my blog post at Debugging OpenID Connect Claim Problems in ASP.NET Core – Tore Nestenius Commented Jan 20 at 7:26
1 Answer
Reset to default 0Please check the token using https://jwt.io/ to see if any value is passed on the claims. If not, please add those claims while generating the token. We have shared the following details on how to fetch claims from the token.I hope this solution is okay for you.
var age = info.Principal.Claims.FirstOrDefault(x => x.Type == "").Value;