0

我在使用 Apple 登录和 Firebase 身份验证时遇到错误:"MISSING_OR_INVALID_NONCE : Nonce is missing in the request."

我能够找到的唯一其他情况类似于以下问题,但是他们更新 pod 文件的解决方案不起作用。

在 iOS 13 上的 Swift 中使用 Apple for Firebase 设置登录时出错的原因是什么?

错误

Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={FIRAuthErrorUserInfoNameKey=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information., NSUnderlyingError=0x2807c6ee0 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
    code = 400;
    errors =     (
                {
            domain = global;
            message = "MISSING_OR_INVALID_NONCE : Nonce is missing in the request.";
            reason = invalid;
        }
    );
    message = "MISSING_OR_INVALID_NONCE : Nonce is missing in the request.";
}}}}

登录按钮点击方法

    let appleIDProvider = ASAuthorizationAppleIDProvider()
    let request = appleIDProvider.createRequest()
    request.requestedScopes = [.fullName, .email]
    
    let nonce = randomNonceString()
    currentNonce = nonce
    request.nonce = sha256(nonce)

中的部分ASAuthorizationController

    let firebaseCredential = OAuthProvider.credential(withProviderID: "apple.com", idToken: identityToken!, accessToken: currentNonce)

在设置后打印 nonce 值,在作为参数发送之前显示它们确实是相同的,添加到适当的请求中,但服务仍然给我这个错误。

firebase 和 GoogleService-Info.plist 中的 BundleID 相同,该应用程序适用于 Google Sign In 和 Firebase。我已经尝试发送原始随机数、散列随机数、不同的散列方法,除了这一件事之外,一切似乎都很好,而且没有真正的调试方法。

4

1 回答 1

0

您没有提供rawNonce- 您正在使用该方法accessToken

通过执行以下操作来修复它:

OAuthProvider.credential(withProviderID: "apple.com", idToken: identityToken!, rawNonce: currentNonce)

在您链接的答案中,他们说 Xcode 会错误地尝试rawNonce使用修复来accessToken代替 - 这是不正确的。修复了这种情况下的pod update错误。

在iOS SDK的 Firebase文档中,他们还使用了rawNonce您应该使用的方法。您不想在这里使用散列随机数,而是使用您存储在currentNonce.

于 2021-09-18T00:16:00.197 回答