Home > Blockchain >  Sign In With Apple Firebase producing "FIRAuthErrorCodeMissingOrInvalidNonce"
Sign In With Apple Firebase producing "FIRAuthErrorCodeMissingOrInvalidNonce"

Time:07-23

I am trying to create an iOS app in which a user logs in using the new "Sign in With Apple Id" Button. I implemented this by:

  1. Having the user sign in once and storing their email, identityToken, and nonce in the Keychain as well as in Firebase. (This works - I have verified that the correct data is stored both in the Keychain and in Firebase)
  2. Once the user leaves the app and re-opens it, I attempt to pull their existing credentials from the Keychain (I have verified that the correct data is pulled from the Keychain)
  3. Once I have the existing credentials from the Keychain, I send them off to Firebase to check if the user already exists, and I keep getting back the FIRAuthErrorCodeMissingOrInvalidNonce / 17094 error, despite the fact that I printed out the nonces before and after being stored in the Keychain and they are identical!!

Any ideas on why this might be happening? I am sure that I am NOT using the sha256 or Data verison of the nonce.

CodePudding user response:

SOLVED: For future readers - as of Swift 5.5, it appears that Firebase expects "Sign In With Apple" users to use Auth.auth().signIn(with: credential) only the FIRST time the user signs in. Once the user has been registered, you are then supposed to use Auth.auth().currentUser?.reauthenticate(with: credential)!

Note that this is a bit confusing, since users that sign in the "traditional" way (i.e username password) can use Auth.auth().createUser(withEmail: email, password: password) for both sign-in AND reauthentication.

  • Related