ios - ASAuthorizationAppleIDCredential : How to check in backend server that the credential is valid?

标签 ios objective-c swift xcode ios13

这个问题已经存在:





Apple Sign In : Validating identityToken at server side

2年前关闭。




我正在通过 Apple 登录实现用户身份验证。当身份验证成功时,授权 Controller 调用 authenticationController:didCompleteWithAuthorization: 委托(delegate)函数,应用程序使用该函数将用户的数据存储在钥匙串(keychain)中。

func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
    if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential { 

      .. send the authorizationCode / identityToken / user and email to the server. 
         server must verify that everything is valid and is yes login the user ...

  }
}

如何在我的后端服务器中验证授权的真实性?他们的任何苹果端点是否在某处可用(就像谷歌对 https://oauth2.googleapis.com/tokeninfo?id_token= 所做的那样)来为我验证授权?

最佳答案

您需要联系您的后端以了解后端支持的登录类型。如果他们使用的是 appleIDCredential.authorizationCode 或 appleIDCredential.identityToken,请使用它们。

对于我的情况,我使用的是 firebase,那么这可以使用 OAuthProvider 来完成,它可以使用以下方式创建:

OAuthProvider.credential(withProviderID: <#T##String#>, idToken: <#T##String#>, rawNonce: <#T##String?#>, accessToken: <#T##String?#>)

enter image description here资料来源:苹果文档

关于ios - ASAuthorizationAppleIDCredential : How to check in backend server that the credential is valid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61313137/

相关文章:

ios - 在启动时在自己的应用程序中使用自定义键盘应用程序扩展。苹果 8-9

ios - 我可以将应用程序设置为在 iOS 上的设备空闲时运行吗?

objective-c - 在 Obj-C 中获取 AppleScript 返回值

swift - “ fatal error :在展开可选值时意外发现nil”是什么意思?

ios - UICollectionView 的框架未正确更新为 UITableViewCell subview

ios - 根据 contentSize 调整自定义 UITableViewCell 中的 UITextView 大小

ios - 在 iOS 的 Google Maps SDK 中启用方向

objective-c - 如何从同一个 NIB(源于 UITabController)加载 UIView?

iphone - 如何在 UINavigationController 中正确继承 UITableViewController?

objective-c - 来自 NSString 的 NSDate