Error while geting Firebase Phone Auth OTP

9,860

Solution 1

@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

Solution 2

Enable Phone option in the Firebase Console under Authentication

Solution 3

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.

Share:
9,860
Admin
Author by

Admin

Updated on December 25, 2022

Comments

  • Admin
    Admin over 1 year

    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