"This app is not authorized to use Firebase Authentication" in Emulator

56,819

Solution 1

In order to prevent abuse the firebase phone authentication wont work in emulator.

But if you want it for testing purpose then you should add use some testing phone number in firebase console that will work in emulator.

Go to your firebase console -> Authentication -> SIGN-IN Method -> Phone and check the "Phone numbers for testing (optional)" field.

enter image description here

Solution 2

sha1 generation in android studio:

Select Gradle in android studio from right panel

Select Your App

In tasks -> android-> signingReport

Double click signingReport.

You will find the sha1 fingerprint in the "Gradle Console"

add this sha1 fingerprint in firebase console

Solution 3

OK, so it is a documented error. https://github.com/firebase/FirebaseUI-Android/issues/790 and https://github.com/firebase/FirebaseUI-Android/issues/868

in order to prevent abuse you can't user Phone Auth on an emulator.

docs are here: https://firebase.google.com/docs/auth/android/phone-auth#before-you-begin

Also, note that phone number sign-in requires a physical device and won't work on an emulator.

UPDATE Take a look at Prasanna Anbu's answer.

Solution 4

After spending the whole Day figuring out what was the issue. I’ve found the culprit! It was in the App Signing for Google Play that we have opted-in. We need to register the SHA-1 from the App Signing itself. It can be found in the inside Google Play Console under Setup > App Integrity. It will have two types of certificate:

1.Upload certificate: this is the information of the certificate from the keystore that uploaded. This is needed to be the same with the keystore for app signing locally as the Google Play will verify the uploaded app to match with this signed certificate.

2.App Signing certificate: after uploaded the app, Google will replace the upload certificate with this certificate. This is a new certificate that will be used for published app in Play Store.

With those information, I just realize that we hadn’t registered the SHA-1 for the App Signing certificate which being used by published app. So, I added the SHA-1 (also the SHA-256, just in case needed) fingerprints in the Firebase > Project Setting for the app (Don’t forget to update the latest config file after added the fingerprints).

So After adding your your SHA Fingerprints your Firebase SHA certificate fingerprints will look like this:

enter image description here

Now Save Changes then Go back to your App and test it again it will work now!.

Solution 5

Your SHA1 key is not registered in your firebase console. Simply generate SHA key as shown in pic below, copy the SHA key from Android Studio terminal and add it in Firebase console project settings:

enter image description here

Also make sure you are using a release keystore to generate this key

enter image description here

enter image description here

After this generate your SHA1 fingerprint else your users will face SHA1 error on phone authentication.

Hope it help somebody.

Share:
56,819
Razvan Cristian Lung
Author by

Razvan Cristian Lung

I'm a forward thinking developer offering more than two years of experience building, integrating, testing and supporting Flutter and Android applications. I like projects that put efficiency and user experience first. Though sometimes this might be tough, I like to be presented to difficult situations. I've been learning Android as a hobby, but it soon became one of my favorite things to do. I like to make full use of the Firebase SDK. And since Flutter came out I just fell in love with it. It is so versatile and performant. Take note: This is the future. (Fuchsia I'm waiting for you)

Updated on July 09, 2022

Comments

  • Razvan Cristian Lung
    Razvan Cristian Lung almost 2 years

    I'm getting this error when I try to run my app on emulator.

    What I've done:

    1. I'm using Firebase-UI and running Android O
    2. I have the Play Store updated.
    3. I've added all the SHA-1 code to Firebase console and the package name matches.

    In fact when I run the app on a real device it runs perfectly and I can login.

    This app is not authorized to use Firebase Authentication. Please verify that the correct package name and SHA-1 are configured in the Firebase Console.
     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. Is app running on a physical device? ]
     at com.google.android.gms.internal.jz.zzK(Unknown Source:239)
     at com.google.android.gms.internal.kp.zza(Unknown Source:2)
     at com.google.android.gms.internal.kq.run(Unknown Source:37)
     at android.os.Handler.handleCallback(Handler.java:789)
     at android.os.Handler.dispatchMessage(Handler.java:98)
     at android.os.Looper.loop(Looper.java:164)
     at android.app.ActivityThread.main(ActivityThread.java:6541)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    
  • Razvan Cristian Lung
    Razvan Cristian Lung over 6 years
    I already said that I've added the SHA-1 certificate, the Auth process works perfectly on a real device.
  • Razvan Cristian Lung
    Razvan Cristian Lung over 6 years
    I already said that I've added the SHA-1 certificate, the Auth process works perfectly on a real device.
  • John M.
    John M. over 6 years
    Is there any way to run it on an emulator though?
  • Razvan Cristian Lung
    Razvan Cristian Lung over 6 years
    /:) No. But you can still try and share.
  • Manspof
    Manspof almost 6 years
    @RazvanCristianLung I'm face this issue in real device(android), how did you solve it?
  • Razvan Cristian Lung
    Razvan Cristian Lung almost 6 years
    does your device run a custom ROM?
  • Prasanna Anbazhagan
    Prasanna Anbazhagan almost 6 years
    You can use emulator with testing phone number.
  • Raj
    Raj over 5 years
    I get this generic error "Error adding test phone number" when adding a test phone number via this screen
  • Prasanna Anbazhagan
    Prasanna Anbazhagan over 5 years
    @emaillenin Make sure the phone number you are adding is not logged/registered before. If the number is already present in authentication then you cannot add that as test account
  • Razvan Cristian Lung
    Razvan Cristian Lung over 5 years
    Please read the whole question. I already said I've added the SHA-1 fingerprint and I've added and there is an approved answer to this question.
  • Luvnish Monga
    Luvnish Monga about 5 years
    After build types -> signing config -> select config -> OK. It's doing nothing. Can you please tell where do I see release SHA1 key?
  • Hitesh Sahu
    Hitesh Sahu almost 5 years
    In the terminal of Android Studio
  • Uday
    Uday about 4 years
    This saved my lot of time man. I tried all other solutions mentioned, but nothing worked out. I do not know why others missed this preliminary steps, but this point helped me a lot. Thanks bro.
  • Anjana
    Anjana about 4 years
    Worked like charm !! Thanks :)
  • Elad
    Elad about 4 years
    Yes that was my problem!
  • wakeupoj
    wakeupoj almost 4 years
    TY! I was using device for testing (not emulator). This was the only thing I found that solved this error: FirebaseUiException: There was an error while trying to get your package certificate hash.
  • sanevys
    sanevys over 3 years
    Thank you very much!
  • Martin Braun
    Martin Braun almost 3 years
    If you cannot find the task in gradle: stackoverflow.com/a/67493124/1540350
  • Martin Braun
    Martin Braun over 2 years
    In my case, I had my debug SHA-1 fingerprint, but it wasn't working until I added my SHA-256 fingerprint as well. I recommend to add SHA-1 and SHA-256 of release and debug keystores to play safe.
  • Deepak Patankar
    Deepak Patankar over 2 years
    Thanks a lot for this answer, it solved my issue