var userEmail = User.FindFirstValue(ClaimTypes.Email); --> getting null
var email = User.Claims.FirstOrDefault(c => c.Type == "emails")?.Value; --> getting valid email
options.TokenValidationParameters.NameClaimType = "name";
我正在开发 .net core 5。我的问题是 c.type 获取电子邮件,这就是它返回 null 的原因。对此有什么想法吗?
最佳答案
可能您的声明是自定义定义的。
因此,ClaimTypes.Email
的标准值在 System.Security.Claims.ClaimTypes
internal const string ClaimType2005Namespace = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims";
...
public const string Email = ClaimType2005Namespace + "/emailaddress";
相反,您对电子邮件的声明被定义为“电子邮件”。
您的代码中有自定义定义吗?
关于c# - 声明类型为 "emails",然后 ClaimTypes.Email 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68763526/