问题描述
所以我尝试在我的 Spring Boot 后端应用程序中使用 Apple Sign in with REST API,一切正常!在我尝试访问用户名之前,即使我在范围内要求 name
,苹果似乎也没有发回该名称,并且文档清楚地表明他们不提供用户信息 uri,但是 {{ 1}} 似乎在响应负载中返回一个 AppleJS
对象
是的,我实现了自定义 OIDC UserDetails 服务。
user
.
public class CompactOAuth2UserService implements OAuth2UserService<OidcUserRequest,OidcUser>
解决方法
看起来 name
范围需要包含在 /auth/authorize
端点的查询参数中。然后它将作为您提到的 user
对象包含在响应中。注意:不过,它似乎会拆分名字和姓氏。
来自:https://developer.apple.com/forums/thread/118209
要在 id_token
中请求用户信息(假设您通过 /auth/authorize
REST API 请求),您需要包含 scope
查询参数,该参数支持以下值— name
和 email
。您可以请求一个、两个或一个都不请求。
注意:对多个范围使用空格分隔和百分比编码;例如,"scope=name%20email"
。
处理响应
当“使用 Apple UI 登录”出现在打开的浏览器选项卡中时,用户可以登录并接受您应用的任何条款和条件。 Apple 处理授权请求后,响应的处理取决于 response_mode 中的值:
...
成功的响应包含以下参数:
... 用户
- 一个 JSON 字符串,包含在 scope 属性中请求的数据。返回的数据格式如下: { "name": { "firstName": string,"lastName": string },"email": string }