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
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.
There is currently no way to change the length of the verification code that Firebase uses.
@CubeRootX and @user13864571
Your problem related to SHA1 and SHA256 keys. You have to add them to authenticate your certs.
Goto
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
Error 400 means bad request, it can be due to any of the following three reasons:-
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.
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
Follow the documentation if issue in not resolved.
Enable Phone option in the Firebase Console under Authentication
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With