我解決它通過加入我需要在AccountController.ExternalLoginCallback
這樣的權利要求:
//Add E-Mail claim even if client didn't ask for it
if (claims.Exists(c => c.Type.Equals(ClaimTypes.Email))) {
additionalClaims.Add(new Claim(JwtClaimTypes.Email, claims.FirstOrDefault(x => x.Type.Equals(ClaimTypes.Email)).Value));
}
然後我通過依賴性添加的權利要求的access_token
注入我ProfileService
類和添加在MyProfileService.GetProfileDataAsync
這樣的權利要求:
public Task GetProfileDataAsync(ProfileDataRequestContext context)
{
var claims = new List<Claim>();
Claim emailClaim = context.Subject.Claims.Where<Claim>(claim => claim.Type.Equals(JwtClaimTypes.Email)).FirstOrDefault();
if (emailClaim != null)
{
claims.Add(emailClaim);
}
context.IssuedClaims = claims;
return Task.FromResult(0);
}
從谷歌登錄返回的Id令牌已包含電子郵件,沒有你專門要求它... https://developers.google.com/identity/protocols/OpenIDConnect#obtainuserinfo – Mashton