"MISSING_OR_INVALID_NONCE : Nonce is missing in the request."

Viewed 735

I am getting an error using Apple Sign In with Firebase Auth: "MISSING_OR_INVALID_NONCE : Nonce is missing in the request."

The only other case I've been able to find is similar to the following question, however their solution of updating the pod file does not work.

Cause of error setting up Sign in with Apple for Firebase in Swift on iOS 13?

Error:

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.";
}}}}

Login Button Clicked Method:

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

Section in ASAuthorizationController:

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

Printing the nonce values after being set, before being sent as a parameter shows that they are indeed the same, added to the appropriate requests, but the service is still giving me this error.

The BundleID is the same in firebase and GoogleService-Info.plist, the app works with Google Sign In and Firebase. I've tried sending the raw nonce, the hashed nonce, different hash methods, everything seems to be okay except for this one thing, and there's no real way to debug it.

1 Answers

You are not providing the rawNonce - you are using the method with accessToken instead.

Fix it by doing the following:

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

In the answer you linked, they said that Xcode would mistakingly try fix rawNonce to use accessToken instead - which is incorrect. The pod update fixed the error in this case.

In the Firebase docs for the iOS SDK, they also use the method with the rawNonce as you should. You do not want to use the hashed nonce here, but rather the value you stored in currentNonce.

Related