Christian Medallada
Christian Medallada

Reputation: 94

How to fix claim types error in ASP.NET ? I'm trying to fetch gender and date of birth, but returned Null but with email and name it is being returned

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);

enter image description here

Upvotes: 0

Views: 42

Answers (1)

Dattatray Patil
Dattatray Patil

Reputation: 21

Please 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;

Upvotes: 0

Related Questions