最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

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;

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论