35

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Faslur Rajah
  • 861
  • 2
  • 10
  • 17

11 Answers11

34

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.

Ayush Surana
  • 1,776
  • 1
  • 12
  • 16
  • I enabled Android Device Verification from google cloud and created a credential key. But how to connect it with my firebase project? – Faslur Rajah Nov 22 '20 at 08:57
  • 3
    So you have enabled the Device Check API via this link? https://console.cloud.google.com/apis/library/androidcheck.googleapis.com – Ayush Surana Nov 22 '20 at 08:59
  • @AyushSurana Is your Firebase OTP autoread working? – naman Nov 24 '20 at 13:25
  • 5
    Hi guys, I implement All mentioned solution but none of working, kindly Help me to get out of this issue – Muhammad Faisal Dec 02 '20 at 13:28
  • getting same error in react native none of the above methods working – Abhi Dec 02 '20 at 18:53
  • 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. – Jeaf Gilbert Jul 13 '22 at 14:24
  • 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 android` – Jeaf Gilbert Jul 13 '22 at 14:38
14

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.
Ilham Safeek
  • 217
  • 1
  • 5
  • 15
  • 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. thanks – Gavin Thomas May 09 '23 at 21:09
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.

Smack Alpha
  • 1,828
  • 1
  • 17
  • 37
Armar
  • 249
  • 3
  • 7
  • 1
    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 console – Azhar Ali Mar 21 '21 at 23:51
  • Do we require, implementation 'com.google.android.gms:play-services-safetynet:17.0.1' For this to work? – Ashwin Balani Dec 31 '21 at 16:17
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.

Muhammad Kashif
  • 253
  • 3
  • 6
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.

Vela
  • 87
  • 11
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.

Hadi Pawar
  • 1,090
  • 1
  • 11
  • 23
  • Well, it worked for me maybe something else is wrong with your code. – Hadi Pawar Mar 23 '21 at 11:24
  • 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? – Kishan Solanki Mar 23 '21 at 11:44
  • 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 . – Hadi Pawar Mar 23 '21 at 13:14
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.

Khaledonia
  • 2,054
  • 3
  • 15
  • 33
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

Satish Singh
  • 71
  • 1
  • 2
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.

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

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.

  • 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](/help/how-to-answer). – Community Jun 22 '23 at 00:54