Firebase phone authentication is not working on Android real device
Asked Answered
I

12

42

I've been trying to achieve phone auth using Firebase authentication. It's working with an android emulator. I used a test number and a real number in the emulator. Both works. But only the test number is working with a real device and throwing this exception for other numbers

Error is:[firebase_auth/missing-client-identifier] This request is missing a valid app identifier, 
 meaning that neither SafetyNet checks nor reCAPTCHA checks succeeded. 
 Please try again, or check the logcat for more details.

I setup SHA key in firebase also.

Ivatts answered 22/11, 2020 at 8:23 Comment(0)
H
36

I am guessing you have not enabled the Device Check API. All you need to do is enable the Device Check API on the cloud platform.

I think after some updates they have made this change that for Safety Net you need SH1 Authentication along with enabling Device Check API.

You can follow the Steps as mentioned here.

Once you enable the device check api. Restart your application. It should work like a charm.

Do lemme know if you need further steps.

Headmost answered 22/11, 2020 at 8:42 Comment(7)
I enabled Android Device Verification from google cloud and created a credential key. But how to connect it with my firebase project?Ivatts
So you have enabled the Device Check API via this link? console.cloud.google.com/apis/library/…Headmost
@AyushSurana Is your Firebase OTP autoread working?Polinski
Hi guys, I implement All mentioned solution but none of working, kindly Help me to get out of this issueLasley
getting same error in react native none of the above methods workingTensor
I'm having problem getting this error through Android emulator. I have added my debug SHA256 in SafetyNet (Firebase Console > Project Settings > App Check. I have enabled Android Device Verification and its key is already in google-services.json. I also have put implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0' in app/build.gradle dependencies. But still no luck.Imitative
Turns out I missed to input DEBUG SHA1 in Firebase Console > Project Settings > General (Notice this is not App Check tab!) > Project. Put DEBUG SHA1 in there! To get your SHA1 and SHA256 DEBUG version, use this command line in ROOT PROJECT (not android folder): keytool -list -v -keystore ./android/app/debug.keystore -alias androiddebugkey -storepass android -keypass androidImitative
Y
19

SafetyNet is newly developed feature for android. But solved the issue without doing any changes in the App.

Following steps helped me to solve.

Release Version

  1. Google Signs the Appbundle when you upload. So, Find and copy the SHA1 key of the app signed by google. Google Play Console - App Signing Key

enter image description here

  1. Navigate to your project -> Project Settings in Firebase Console and add SHA1 key by clicking on Add fingureprint. enter image description here

Debug version

  1. Navigate to android directory of your project with following command with Terminal.

cd android

  1. Generate app signingReport and copy the SHA1 key

gradlew signingReport

on Mac :

./gradlew signingReport

enter image description here

  1. Add the SHA1 key in firebase app.
Youngyoungblood answered 17/10, 2021 at 4:38 Comment(1)
I didn't realize, when I run this command, you need the variant debug and release, not any of the other numerous outputs! This did work. thanksFolkmoot
R
6

Android has added SafetyNet you can read more here. But what you have to do is

1. enable the Android Device verification api here. and

2. If you haven't yet specified your app's SHA-256 fingerprint, do so from the Settings Page of the Firebase console. For more info read details here.

Regicide answered 18/3, 2021 at 9:53 Comment(3)
This solution works for me Both steps are required according to documentation 1. Enable Android Device Verification 2. Add SHA-256 finger print to firebase consoleIntransigeance
Do we require, implementation 'com.google.android.gms:play-services-safetynet:17.0.1' For this to work?Camillacamille
error saying "Failed to load"Paper
G
4

I resolved my issue by removing by old android studio sha-1 and sha-256 keys from firebase and adding a new one from the latest android studio.

Gluteal answered 1/3, 2021 at 16:7 Comment(0)
R
3

I have fixed this error. In my case I added two android projects with same SHA-1 in single firebase project. Once I removed one project from firebase project. Now it is working for me.

Ridgeway answered 9/3, 2021 at 7:40 Comment(0)
M
1

I found this after much searching and should work for you or anyone else who stumbles here:

Put this line inside app/build.gradle under dependencies

implementation "androidx.browser:browser:1.2.0"

It is because its do reCAPTCHA verification and opens up browser.

Moreira answered 4/2, 2021 at 17:47 Comment(3)
Well, it worked for me maybe something else is wrong with your code.Moreira
If the code has something wrong then it shouldn't be working in debug mode. Even, OTPs are coming for the testing phone numbers in live mode, but not working only in those numbers which are never registered. Can you add the reference URL from where did you find that this dependency should be added for Firebase Authentication?Carnes
The problem for me was that firebase on OTP screen wanted to open a browser for recaptcha i believe its the default behaviour now. Since browser was missing it wasn't working and it worked when I got it in there . So since I m not sure what exactly your problem is I cant help .Moreira
V
1

There are two ways Firebase Authentication accomplishes this:

SafetyNet: If a user has a device with Google Play Services installed, and Firebase Authentication can verify the device as legitimate with Android SafetyNet, phone number sign-in can proceed.

or

reCAPTCHA verification: In the event that SafetyNet cannot be used, such as when the user does not have Google Play Services support, or when testing your app on an emulator.

So your solution is either one of two

  • Retest on a real device

  • Add reCAPTCHA verification functionality to your app so you can proceed with your emulator.

Vasculum answered 28/3, 2021 at 16:3 Comment(0)
P
1

For Android, Firebase requires you to add your app's SHA-1 and SHA-256 keys to the Firebase console. You can get these keys by running the following command in your project directory:

  1. cd android
  2. ./gradlew signingReport
Pescara answered 30/5, 2024 at 7:46 Comment(0)
T
0

This was worked for me :- If your app is published on the play store, Copy App signing key certificate from the Google Play console (Release > Setup > App Integrity page). Insert your signing key to your Firebase Console(Project settings Page).

Follow this link - https://developers.google.com/android/guides/client-auth

Taka answered 7/5, 2022 at 8:47 Comment(0)
D
0

I removed my phone number from phone number for testing on firebase and it was worked for me when working on real device not emulator.

Doubleacting answered 25/8, 2022 at 21:23 Comment(0)
H
0

Actually, two of my apps had the same OAuth2 client IDs which were creating the issue for Google Firebase Authentication to send the SMS OTP. How I solved this issue is mentioned as:

  1. Opened my project in the Google Cloud Platform dashboard.
  2. Moved to Credential Section
  3. Find the project which has the same key conflicting your own project under OAuth 2.0 Client IDs. Click to open it.
  4. Remove the IDs
  5. Restart your project and it's Done!

You can find the official help here.

Feel free is you have any issues on this topic. Thanks

Hluchy answered 18/5, 2023 at 7:11 Comment(0)
A
0

I added the debug SHA-1 and SHA-256 of the debug keystore by android studio to the firebase project (general settings), as explained here: https://developer.android.com/studio/publish/app-signing#debug-mode.

Azobenzene answered 18/6, 2023 at 22:40 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Casuistry

© 2022 - 2025 — McMap. All rights reserved.