Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Invalid Token" when trying to authenticate phone number using firebase

Tags:

This is my code:

import FirebaseAuth   class AuthPhoneNum {      static func getPhoneNum(phoneNumber: String) {         PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in             if let error = error {                 print(error)                 return             }             UserDefaults.standard.set(verificationID, forKey: "authVerificationID")         }     }      static func verify(verificationCode: String?) {         guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return }         if verificationCode != nil {             let credential = PhoneAuthProvider.provider().credential(                 withVerificationID: verificationID,                 verificationCode: verificationCode!)              Auth.auth().signIn(with: credential) { (user, error) in                 if let error = error {                     print(error)                     return                 }             }         } else {             print("No verification code")         }     }  } 

This is what the console prints out:

Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token." UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL}

What am I doing wrong? Thanks

like image 233
Jordan Tate Avatar asked Jul 13 '17 21:07

Jordan Tate


People also ask

How do I add my phone number to Firebase authentication?

In the Firebase console, open the Authentication section. In the Sign in method tab, enable the Phone provider if you haven't already. Open the Phone numbers for testing accordion menu. Provide the phone number you want to test, for example: +1 650-555-3434.

What is auth token in Firebase?

When a user or device successfully signs in, Firebase creates a corresponding ID token that uniquely identifies them and grants them access to several resources, such as Firebase Realtime Database and Cloud Storage. You can re-use that ID token to identify the user or device on your custom backend server.


1 Answers

I was also experiencing this problem. Checked the following:

  • Correct bundle Id
  • Correct Google-Info.plist
  • Correct aps-environment value
  • Correct APNS token type when calling auth.setAPNStoken (.unknown for auto detect)

Nothing helped until in Firebase app settings I uploaded the APNS authentication key (p8) instead of certificates - I used those certificates before for push notifications only and everything was working fine but for phone number notifications something went wrong.

like image 110
algrid Avatar answered Oct 06 '22 18:10

algrid