如何使用 IdentityServer4 从苹果登录中获取名字和姓氏?

How can I get firstName and lastName from apple sign in using IdentityServer4?

我正在使用 IdentityServer4 对我的应用程序中的用户进行身份验证。

我已将苹果添加为外部供应商。添加范围:电子邮件和姓名。 Apple 表示,他们发送的用户信息不是在 id_token 中,而是在单独的模型中:

user: { "name": { "firstName": string, "lastName": string }, "email": string }

看起来 id_token 中也添加了电子邮件,我实际上是从外部用户声明中在外部控制器中获取它的。但是没有名字、名字或姓氏。我如何使用 IdentityServer4 获取此信息?

您需要从 apple 返回的用户对象中提取这些道具,就像在 https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/blob/dev/src/AspNet.Security.OAuth.Apple/AppleAuthenticationHandler.cs#L167 上所做的一样 如果您在 AspNet.Security.OAuth.Apple would be easier as the code already there. Checkout docs 上使用 .AddApple 扩展程序以获得详细说明。