I want to authenticate phone number Firebase with SafetyNet and not reCAPTCHA verification. I am following the Firebase documentation here: https://firebase.google.com/docs/auth/android/phone-auth
- In the Google APIs Console I enabled the Android Device Verification API.
- In the Firebase console I added the SHA-256 fingerprint.
- Reinstalled google-service.json and added it to the project.
It always redirects me to a web page to verify I am not a robot. I tried removing
implementation 'androidx.browser:browser:1.3.0'
But the app crashes.
This is the code I am using for SafetyNet and it always succeeds but then shows the web page. I want to know how to prevent the app from always redirecting to reCAPTCHA verification although the attest function works fine.
private fun checkSafetyNet() {
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
== ConnectionResult.SUCCESS
) {
val nonce =
(getString(R.string.app_name) + Random.nextInt(100) + getString(R.string.otp_verification)).toByteArray()
SafetyNet.getClient(this.requireActivity())
.attest(nonce, API_KEY)
.addOnSuccessListener {
// Indicates communication with the service was successful
setFirebasePhoneVerificationCallbacks()
startPhoneNumberVerification()
}.addOnFailureListener { e ->
// An error occurred while communicating with the service.
if (e is ApiException) {
// An error with the Google Play services API contains some
// additional details.
val apiException = e as ApiException
Log.i("SAFETYERROR", apiException.message.toString())
// You can retrieve the status code using the
// apiException.statusCode property.
} else {
// A different, unknown type of error occurred.
Log.d("SafetyNetError", "Error: " + e.message)
}
}
} else {
// Prompt user to update Google Play services.
}
}