【问题标题】:ASAuthorizationAppleIDCredential : How to check in backend server that the credential is valid? [duplicate]ASAuthorizationAppleIDCredential :如何在后端服务器中检查凭证是否有效? [复制]
【发布时间】:2020-04-20 08:08:52
【问题描述】:

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

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= 所做的那样)来为我验证授权?

【问题讨论】:

    标签: ios objective-c swift xcode ios13


    【解决方案1】:

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

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

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

    来源:Apple 文档

    【讨论】:

    • 你没看懂问题:(我要验证授权的真实性
    • 对于后端你需要实现这个:developer.apple.com/documentation/sign_in_with_apple/…
    • 谢谢,但是具体怎么做呢?我找不到要调用的端点:(
    • GET appleid.apple.com/auth/keys 响应如下:` { "keys": [ { "kty": "RSA", "kid": "AIDOPK1", "use": "sig", "alg": "RS256", "n": "lxrwmuYSAsTfn-lUu4goZSXBD9ackM9OJuwUVQHmbZo6GW4Fu_auUdN5zI7Y1dEDfgt7m7QXWbHuMD01HLnD4eRtY-RNwCWdjNfEaY_esUPY3OVMrNDI15Ns13xspWS3q-13kdGv9jHI28P87RvMpjz_JCpQ5IM44oSyRnYtVJO-320SB8E2Bw92pmrenbp67KRUzTEVfGU4-obP5RZ09OxvCr1io4KJvEOjDJuuoClF66AT72WymtoMdwzUmhINjR0XSqK6H0MdWsjw7ysyd_JhmqX5CAaT9Pgi0J8lU_pcl215oANqjy7Ob-VMhug9eGyxAWVfu_1u6QJKePlE-w", "e": "AQAB" } ] }
    • 您可以阅读这篇文章:sarunw.com/posts/sign-in-with-apple-3
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    • 2015-08-28
    • 2021-03-21
    • 2010-11-02
    相关资源
    最近更新 更多