此应用程序未被授权使用 Firebase 身份验证。请确认 Firebase 控制台中配置了正确的包名和 SHA-1

Firebase auth 工作正常,调试构建突然开始失败,没有任何代码更改,记录下面的消息

D/PhoneAuthActivity (7392) : signInWithCredential: fault: com.google.firebase.auth.FirebaseAuthException: 此应用程序未被授权使用 FirebaseAuthentication。请确认在 Firebase 控制台中配置了正确的包名和 SHA-1。[应用程序验证失败]。

在成功登录和失败之间唯一值得注意的操作是 android 工作室升级。

102180 次浏览

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

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.


UPDATE (12th May 2022):


  • Find SHA1 and SHA-256 BOTH the certificate fingerprints from the play store console.

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

SHA1 and SHA256 from play-store console

  • Place BOTH SHA1 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

Ref: Authenticating Client Using Play App Signing


TAKE CARE BELOW POINTS


  1. Also insert local SHA1 and SHA-256. Get it by ./gradlew signingReport . Get more info from here.
  2. 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).
  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.
  6. After doing all the stuff, Please make sure you are using the latest/updated google-services.json file.

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

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.

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.

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

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.

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.

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.

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.

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]

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

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.

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.

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.

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.

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.

Step 1 Open the android studio and click on Gradle at top of the right-hand side.

Step 2 Click on signingReport OR search it in Gradle(check the diagram)

Step 3 Copy the SHA-1 from bottom

First Image

Step 4 go to the firebase console and open your project setting in firebase.

Secound Image

Step 5 click on AddFingurePrint and paste the SHA1

Step 6 Again go to android studio and copy the SHA-256 and click on addFingurePrint button a second time and past it and save it

You can also get the SHA1 and SHA-256 of your signing certificate using the Gradle signingReport command:

./gradlew signingReport

Now add the SHA1 and SHA-256 in the project setting in firebase here.

enter image description here

Just add a SHA1 and SHA-256 into your firebase fingerprint

Step1: Run this command into your project terminal "cd .\android" and then keytool -list -v -keystore c:\Users\User_name.android\debug.keystore -alias androiddebugkey -storepass android -keypass android You will get a SHA keys Step 2: Copy those keys and add them inside the firebase fingerprint inside Project settings->users

If you are working with react-native. Please find correct debug.keystore which avaialbe in android -> app -> ./debug.keystore

I recommended to use this tool to find sha-1 and sha256.

https://keystore-explorer.org/downloads.html

I use "./gradlew signingReport" command but it's not give me correct details. It's may some error from my side but i strongly recommended to confirm you sha's (sha1 and sha256) detail with following tool .

https://keystore-explorer.org/downloads.html

I had the SHA-1 and SHA-256 fingerprints for app. But still I was getting the error. Well, I had the fingerprints for my PRODUCTION keystore. When I added a new set of fingerprints for my debug keystore - it all worked just fine

If you have followed the accepted answer without success, try updating all Firebase dependencies, clear cache and try again

run with ctrl+ enter

gradle signingReport
----------
Variant: release
Config: release
Store: <<Path to keystore.jks>>
Alias:<<Alias Name>>
MD5: <<---------------->>
SHA1: <<---------------->>
SHA-256: <<---------------->>
Valid until: Tuesday, 26 October 2049
----------

use release sha key and paste it at firebase console.

The same I had experienced, what happened was , I have newly install windows , therefore debug SHA keys changed, I added new debug sha1,sha256 to firebase console ,

to get SHA keys terminal run cd android , then below Code & pressed with ctrl button

./gradlew signingReport,

if this not works open project level build.gradle file , in top left click open for edit in Android Studio

it will take some time to load then run ./gradlew signingReport