67
votes

Firebase auth was working fine, the debug build suddenly started failing without any change of code, logging the folloing message

D/PhoneAuthActivity( 7392): signInWithCredential:failure:com.google.firebase.auth.FirebaseAuthException: This app is not authorized to use Firebase Authentication. Please verifythat the correct package name and SHA-1 are configured in the Firebase Console. [ App validation failed ].

The only notable action inbetween a successful login and failure is android studio upgrade.

18

18 Answers

63
votes

When you updated Android Studio, the debug key which is used to sign debug apps might have changed. Just add the new SHA-1 checksum of your debug key in the firebase console.

Easiest way would be to connect/sync to firebase from

Tools>Firebase>Authentication>Connect>Sync


If you want to do it manually or for release keystore, first generate SHA-1 checksum using following command:

keytool -list -v -keystore KEYSTORE_PATH -alias ALIAS_NAME

Then copy the SHA-1 checksum and go to:

Firebase Console > Your project > Settings of the app > Add Fingerprint

For more info, read this guide: Authenticating Your Client | Google APIs for Android

130
votes

UPDATE (31-03-2021):


  • Find SHA-1 and SHA-256 BOTH certificateS fingerprint from the play store console.

Play store Console > Your project > Release > Setup > App integrity

SHA1 and SHA256 from play-store console

  • Place BOTH SHA-1 and SHA-256 fingerprints to your firebase app one by one.

Firebase Console > Your project > Settings of the app > Add Fingerprint

Fingerprints added to be in Firebase console


TAKE CARE BELOW POINTS


  1. If you are using an Emulator for phone OTP verification, it won't work since it does not have a sim. So try installing it on your mobile(with sim).
  2. Make sure you are using the latest/updated google-services.json.
  3. Enable app verification step is followed properly. and Android Device Verification is ENABLED.
  4. Make sure the correct project is selected from drop-down while enabling Android Device Verification.
  5. BOTH SHA-1 and SHA-256 fingerprints to be added in the Firebase project.
21
votes

If you are using a Emulator for phone OTP verification it won't work since it does not have a sim. So try installing it to your mobile(with sim) and check if the error persists.

9
votes

Ok i just figured out the issue.. If you are using Play Store app signing, then the SHA1 from you distributed app will be different from the one you are using locally. Make sure you add the SHA1 key from Play Console to your app in the Firebase Console.

9
votes

In case of Linux Machine

Step 1: Go to Physical File Directory of your project in your file system

Step 2: Go to Your project> android>

Step 3: Press right click and open a new terminal in this directory

As shown in the image

Step 4: Run command 'gradlew signingReport'

Step 5: Copy your SHA-1 key or SHA-56 key

Step 6: Go to Firebase Console> Your project> Project Settings> Add Fingerpring

Step 7: Paste your SHA-1 key or SHA-56 key and save.

Now, you are good to go.

Thanks.

5
votes

If you are using Google Internal App Sharing, please note that Google automatically signs your builds with a totally different certificate as stated here, you'll need to find the signing certificate information that is automatically provided for your application build by Google.

To find the certificate;

  1. Sign in to your Play Console.
  2. Select your app.
  3. On the left menu, select Development tools > Internal app sharing.
  4. Select the “App certificate” tab, and then copy the SHA-1 to your firebase console.
4
votes

The latest error occurred

A safety_net_token was passed, but no matching SHA-256 was registered in the Firebase console. Please make sure that this application’s packageName/SHA256 pair is registered in the Firebase Console.

Solution is :

Add also SHA256 in project settings of Firebase Console.

3
votes

This took me two days. I tried the accepted solution (by Nabin Bhandari) but that didn't work for me. Then finally managed to do it as follows.

  1. Go to "Build> Generate Signed Bundle/APK".

  2. If you wish to upload app to play store select "Android App Bundle", otherwise you can use "APK". Then go next.

  3. Now in "Key store path" click "CREATE NEW". Enter the details in dialog box. When you click "OK", you have your key files generated.

  4. Enter the key path, password etc.

  5. Select "debug" or "release" as desired. After this, your signed apk is generated at [project Directory]\app\debug.

  6. Now generate SHA-1 key using (as suggested by: Nabin):

    keytool -list -v -keystore KEYSTORE_PATH -alias ALIAS_NAME

  7. Use adb install app-debug.apk to install the app in the device. Now the app will work.

Dev/Debugging Tip: Install signed APK when Run is used.
When you click run again the signed app is overwritten and you might face the problem again. So there is a need to install signed apk when Run 'app' is clicked.

Add these values to your .gradle file (Module:app):

signingConfigs{
    debug{
        keyAlias 'your key alias'
        keyPassword 'your keypassword'
        storeFile file('keystore path')
        storePassword 'your storepassword'
    }
}

Ref: see here

2
votes

Update your app Fingerprint in firebase it works for me.

Step 1: Get the latest SHA-1 by running this command in terminal For Linux or macOS:

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

For Windows:

keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

Step 2: Go to Firebase Console and delete recently added Fingerprints

Firebase Console > Your project > Project Settings > Delete Fingerprint

Next: Firebase Console > Your project > Project Settings > Add Fingerprint Paste new SHA-1 Fingerprint and save. It will work fine now.

2
votes

Although the step 4 in documentation asks to add SHA-1 alone,
it worked for me only when I added both keys, SHA-1 and SHA-256.

Ref - The first 5 minutes of this video solved this error that I was facing for over 5 days.

1
votes

I have got the same issue and solve as follow

Generate .keystore file like in this document https://facebook.github.io/react-native/docs/signed-apk-android

generated SHA-1 key by this command

keytool -list -v –keystore [PATH]\android\app\my-upload-key.keystore

And copy the SHA1 key under certificate fingerprints and add it firebase app settings->genaral tab->your app section->SHA certificate fingerprints

1
votes

I am posting it late but it's a very simple trick i have found Download this Key Explorer And explore your App signing key(.jks), You'll be able to get SHA-1 & other Keys also. Now copy your SHA-1 from here and add it to firebase console. Steps: Firebase Console > Your project > Project Settings > Add Fingerprint Paste your SHA-1 and save it.

The reason is of this error is while we do testing for debug-apk it uses local systems SHA(that we had already updated over firebase console) but when when it's Release-build & live on Play store, it uses SHA from SigningKey(.jks). So we have to update both fingerprints on console.

1
votes

I am late but it's help to others.

This problem is occur when you use generate signed apk or may be in debug mode you forgot to save SHA-1 & SHA-256 in firebase console.

   The solution for generate signed apk is: Your app must be available on your google 
   play console (Google play store). Copy SHA-1 available in google play console > App 
   Signing and save in firebase console.
1
votes

Before, we could achieve user sign-in in our released app just by using our app's sha-1 certificate,could be generated by android studio. But now, we need to add the sha-1 certificate from the play console's app signing certificate to our firebase's project setting.

And the steps are already answered above by our fellows.

0
votes

Look at this thread: How to get the SHA-1 fingerprint certificate in Android Studio for debug mode?

And you will now how to get sha-1 key of your app easily (without -keytool command) and add id to Firebase console.. Then you must update your google-services.json file in your project.

0
votes

I think this is the easiest solution

See SHA-1 certificate fingerprint from App signing from play store console

  • Play console>Release dashboard>App signing>>Copy SHA-1 key[![How to get SHA-1 Key from Google play console] 1:[ https://i.stack.imgur.com/QvlnC.jpg]How to add SHA-1 key from Play Console to Firebase app

How to add SHA-1 key from Play Console to Firebase app]

0
votes

feature doesnt work on emulator even your mobile number is in physical device you must have to use a physical device to use phone authentication... you issue must be solved if you set up SHA1 key perfectly and still getting this exception

0
votes

I've had this same issue for days. After trying every possible solution I found out my firebase-auth dependency version was (19.3.1) and when I change it to the latest i.e (20.0.3 right now) it worked fine.