11

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
CubeRootX
  • 127
  • 2
  • 9
user13864571
  • 111
  • 1
  • 1
  • 3

5 Answers5

13

@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

Sajid Zeb
  • 1,806
  • 18
  • 32
5

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.

Boken
  • 4,825
  • 10
  • 32
  • 42
Anant Bharti
  • 51
  • 1
  • 4
3

Enable Phone option in the Firebase Console under Authentication

Ishaan Ohri
  • 187
  • 1
  • 2
  • 9
0

I have been stuck here for a week only to find a key I was using was restricted to another app and was therefore failing when trying to use it in my app. So I first removed the restriction in the credentials tab in Android device verification and everything went back to normal

Taio
  • 3,152
  • 11
  • 35
  • 59
0

We need to add one extra step to @Anat Bharti Answer: Enable GCS Device Verification API on Your Project

Enable GCS Device Verification API on Your Project. That solves Everything, You not even asked to Verify capcha on your Physical device.