Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while geting Firebase Phone Auth OTP

I am trying to implement Firebase Phone Verification. I have enabled phone verification on firebase console. I have generated keystore and added the SHA signatures to the console.

dependencies:

dependencies {
    def multidex_version = "2.0.1"
    implementation platform('com.google.firebase:firebase-bom:26.0.0')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics'
    implementation "androidx.multidex:multidex:$multidex_version"
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-core'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'

}

phone_verification.dart

                await FirebaseAuth.instance.verifyPhoneNumber(
                  phoneNumber: '+1234567890',

                  verificationCompleted: (PhoneAuthCredential credential) {
                    print('verificationCompleted');
                    
                  },
                  verificationFailed: (FirebaseAuthException e) {
                    print('verificationFailed');
                    if (e.code == 'invalid-phone-number') {
                      print('The provided phone number is not valid.');
                    }
                    else {
                      print('Some error occoured: $e');
                    }
                  },
                  codeSent: (String verificationId, int resendToken) async {
                    print('codeSent');

                    // Update the UI - wait for the user to enter the SMS code
                    String smsCode = '123456';

                    // Create a PhoneAuthCredential with the code
                    PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.credential(verificationId: verificationId, smsCode: smsCode);
                  
                  },
                  timeout: const Duration(seconds: 60),
                  codeAutoRetrievalTimeout: (String verificationId) {
                    print("Timeout: $verificationId");
                  },
                );

When the above block is executed following error is received. Console Output:

E/FirebaseAuth: [GetAuthDomainTask] Error getting project config. Failed with {
      "error": {
        "code": 400,
        "message": "INVALID_CERT_HASH",
        "errors": [
          {
            "message": "INVALID_CERT_HASH",
            "domain": "global",
            "reason": "invalid"
          }
        ]
      }
    }
     400
V/FA: Recording user engagement, ms: 1165
E/zza: Failed to get reCAPTCHA token - calling backend without app verification
like image 570
user13864571 Avatar asked Nov 06 '20 19:11

user13864571


People also ask

How do I turn off reCAPTCHA in Firebase phone Auth OTP Web?

Don't forget to go in Firebase Project Settings > App check > and Register firebase project in SafetyNet and Play Integrity register with default time token 1 hour and u will remove reCaptcha from phone auth OTP! That's awesome.

Can I customize the Firebase OTP digits default 6 to 4 )?

There is currently no way to change the length of the verification code that Firebase uses.


3 Answers

@CubeRootX and @user13864571

Your problem related to SHA1 and SHA256 keys. You have to add them to authenticate your certs.

Goto

  • Firebase Console of your project
  • Authentication
  • Project Setting (From Setting button near Project Overview)
  • Add fingerprint
  • Add SHA-1 and SHA-256 values of your keystore.

You can get keystores from gradle like this.

./gradlew signingReport

Read this for more information: https://firebase.google.com/docs/auth/android/phone-auth#enable-app-verification

like image 160
Sajid Zeb Avatar answered Oct 16 '22 19:10

Sajid Zeb


Error 400 means bad request, it can be due to any of the following three reasons:-

  1. Check if phone authentication option is enabled in firebase console or not. Enable it.
  2. Check if Android Device Check API is enabled in Google cloud console or not. Enable it.
  3. Check if SHA-1 and SHA-256 are added to your firebase project or not. Add it as follows:

Open your project in firebase console -> Go to project setting -> Click on add fingerprint (at the bottom of the page) -> Add the SHA-1 and SHA-256 values there.

Image for reference

You can get the SHA values of your android studio project as follows:-

Click on gradle on top right side -> task -> android -> signingReport -> Get the SHA values at the bottom after running signingReort Image for reference

Follow the documentation if issue in not resolved.

like image 31
Anant Bharti Avatar answered Oct 16 '22 19:10

Anant Bharti


Enable Phone option in the Firebase Console under Authentication

like image 3
Ishaan Ohri Avatar answered Oct 16 '22 18:10

Ishaan Ohri