在 Web 应用程序中实现 Apple 登录(旧式 ASP.NET,但这无关紧要 - 该问题可以视为简单的 HTML/JS POC),在 Apple 端点上调用方法授权:
https://appleid.apple.com/auth/authorize?client_id=...&redirect_uri=...&response_type=code%20id_token&state=...&response_mode=form_post&scope=name%20email
我想获取用户的名字和姓氏。方法返回如下内容:
{
"state": "xxx",
"code": "yyy",
"id_token": "zzz",
"user": {
"name": {
"firstName":"John",
"lastName":"Doe"
},
"email":"example@privaterelay.appleid.com"
}
}
id_token 是 JWT,由用户的苹果 ID 和电子邮件组成,没有关于姓名或姓氏的数据。如您所见,我可以从 user 属性中获取 name 和 surname。这是我知道的唯一方法。
问题是,Apple 仅在我第一次请求时才返回此数据。这不是错误,而是功能:https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_js/configuring_your_webpage_for_sign_in_with_apple :
Important
Apple only returns the user object the first time the user authorizes the app. Persist this information from your app; subsequent authorization requests won’t contain the user object.
因此,我将这些数据存储在工作流程中,以便稍后将其存储在数据库中。
现在我的问题/疑问:
当用户删除他们的帐户时,我会从数据库中删除他们的所有数据(由于契约(Contract)、法律等原因,我必须这样做)。
当用户通过Apple登录再次注册时,我ping Apple端点,并且我不再获取用户数据(包括姓名和姓氏)(因为上面引用的Apple政策)!
我该怎么做才能得到它?
最佳答案
我正在做苹果登录后端部分,遇到了类似的问题。
IOS 13+
(在请求失败的情况下,您可以要求后端将其放入队列中,应用程序应将其保留在缓存中,直到后端调用成功)。
对于安卓/WEB Flow/IOS 13以下
因此,现在在后端,您将始终使用 apple_user_uuid 标记电子邮件、名字、姓氏,这对于苹果 ID 保持不变。
如果用户删除了您的帐户,请不要删除此映射。直到苹果提供修复。
关于web - Apple 登录,授权方法仅在第一次返回名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63500926/