简体   繁体   English

如何在令牌响应中解码苹果登录 id_token

[英]How to decode apple sign-in id_token in token response

I followed the following blog post to implement Apple sign-in.我按照以下博客文章来实现 Apple 登录。 It was written long time ago when there was no id_token with user info.它是很久以前写的,当时没有带有用户信息的 id_token。 When I request token API I receive JSON with several fields.当我请求令牌 API 时,我收到包含多个字段的 JSON。 The question is how to decode data in id_token field to get email address and user id.问题是如何解码 id_token 字段中的数据以获取电子邮件地址和用户 ID。

Thanks to @Dai,感谢@Dai,

Turns out to be quite easy:事实证明这很容易:

var responseJSON = JObject.Parse(appleTokenResponseString);
var id_token = responseJSON.GetValue("id_token").ToString();
var handler = new JwtSecurityTokenHandler();   
var jwt = handler.ReadJwtToken(id_token);
foreach (var claim in jwt.Claims)
{
     System.Diagnostics.Debug.WriteLine($"{claim.Type}:{claim.Value}");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apple 登录 - 验证 ID 令牌 - Apple Sign-in - Validating ID Token 在 Azure Active Directory B2C 中使用 OpenID Connect 进行 Web 登录会提供 id_token 而不是 access_token - Web sign-in with OpenID Connect in Azure Active Directory B2C gives id_token instead of access_token Azure AD令牌服务不响应refresh_token和id_token - Azure AD token service does't response refresh_token and id_token OWIN Google身份验证-如何获取id_token? - OWIN Google authentication - how to get id_token? Oauth 2.0 | SPA | id_token 如何伪装成访问受限网络资源的 access_token? - Oauth 2.0 | SPA | How does id_token disguise as an access_token for accessing restricted web resources? 如何使用 id_token 从 Azure Function 应用程序获取 Azure access_token? - How get in Azure access_token from Azure Function app with id_token? 如何使用System.Net.Http将access_token和id_token发送到api - How to send an access_token and id_token to an api using System.Net.Http 我如何将计算字段添加到access_token / id_token - How i can add the calculated fields to access_token / id_token 允许将 id_token 而不是访问令牌传递给 api - Allow passing id_token instead of Access Token to api Azure AD B2C - 如何为id_token交换用户名/密码? - Azure AD B2C - how is username/password exchanged for id_token?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM