简体   繁体   English

“此应用无权在模拟器中使用 Firebase 身份验证”

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

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我正在使用 Firebase-UI 并运行 Android O
  2. I have the Play Store updated.我更新了 Play 商店。
  3. I've added all the SHA-1 code to Firebase console and the package name matches.我已将所有 SHA-1 代码添加到 Firebase 控制台和 package 名称匹配。

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)

In order to prevent abuse the firebase phone authentication wont work in emulator.为了防止滥用,firebase 电话身份验证在模拟器中不起作用。

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.但是,如果您希望将其用于测试目的,那么您应该在 firebase 控制台中添加一些可在模拟器中使用的测试电话号码。

Go to your firebase console -> Authentication -> SIGN-IN Method -> Phone and check the "Phone numbers for testing (optional)" field.转到您的 Firebase 控制台 -> 身份验证 -> 登录方法 -> 电话并检查“测试电话号码(可选)”字段。

在此处输入图片说明

sha1 generation in android studio: android studio 中的 sha1 代:

Select Gradle in android studio from right panel从右侧面板中选择 android studio 中的 Gradle

Select Your App选择您的应用

In tasks -> android-> signingReport在任务-> android->signingReport

Double click signingReport.双击签名报告。

You will find the sha1 fingerprint in the "Gradle Console"你会在“Gradle Console”中找到sha1指纹

add this sha1 fingerprint in firebase console在 firebase 控制台中添加这个 sha1 指纹

OK, so it is a documented error.好的,所以这是一个记录错误。 https://github.com/firebase/FirebaseUI-Android/issues/790 and https://github.com/firebase/FirebaseUI-Android/issues/868 https://github.com/firebase/FirebaseUI-Android/issues/790https://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文档在这里: 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.更新看看Prasanna Anbu的回答。

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.我们是在 Google Play 应用签名中选择加入的。 We need to register the SHA-1 from the App Signing itself.我们需要从 App Signing 本身注册 SHA-1。 It can be found in the inside Google Play Console under Setup > App Integrity.它可以在设置 > 应用程序完整性下的 Google Play 控制台内部找到。 It will have two types of certificate:它将有两种类型的证书:

1. Upload certificate : this is the information of the certificate from the keystore that uploaded. 1.上传证书:这是上传的密钥库中的证书信息。 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.这需要与本地应用程序签名的密钥库相同,因为 Google Play 将验证上传的应用程序以与此签名证书匹配。

2. App Signing certificate : after uploaded the app, Google will replace the upload certificate with this certificate. 2.应用签名证书:上传应用后,谷歌将用此证书替换上传证书。 This is a new certificate that will be used for published app in Play Store.这是一个新证书,将用于在 Play 商店中发布的应用程序。

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.有了这些信息,我才意识到我们没有为已发布的应用程序使用的应用程序签名证书注册 SHA-1。 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).因此,我在应用程序的 Firebase > 项目设置中添加了 SHA-1(还有 SHA-256,以防万一)指纹(添加指纹后不要忘记更新最新的配置文件)。

So After adding your your SHA Fingerprints your Firebase SHA certificate fingerprints will look like this:因此,添加您的 SHA 指纹后,您的 Firebase SHA 证书指纹将如下所示:

在此处输入图片说明

Now Save Changes then Go back to your App and test it again it will work now!.现在保存更改然后返回到您的应用程序并再次测试它现在可以工作了!。

Your SHA1 key is not registered in your firebase console.您的 SHA1 密钥未在 Firebase 控制台中注册。 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:只需生成如下图所示的 SHA 密钥,从 Android Studio 终端复制 SHA 密钥并将其添加到 Firebase 控制台项目设置中:

在此处输入图片说明

Also make sure you are using a release keystore to generate this key还要确保您使用的是发布密钥库来生成此密钥

在此处输入图片说明

在此处输入图片说明

After this generate your SHA1 fingerprint else your users will face SHA1 error on phone authentication.在此之后生成您的 SHA1 指纹,否则您的用户将在电话身份验证时面临 SHA1 错误。

Hope it help somebody.希望它可以帮助某人。

You need to configure the SHA-1 in firebase console.您需要在 firebase 控制台中配置SHA-1

You can do it very easily using Android Studio tools.您可以使用 Android Studio 工具轻松完成。

  1. Open Tools -> Firebase in Android Studio.在 Android Studio 中打开Tools -> Firebase
  2. Click any one of the feature, like Authentication or RealtimeDatabase .单击任一功能,例如AuthenticationRealtimeDatabase
  3. Click on the Connect to Firebase and do the required.单击Connect to Firebase并执行所需操作。

or或者

Add it manually.手动添加。 Check out this..看看这个..

How to add SHA-1 to android application 如何将 SHA-1 添加到 Android 应用程序

对我来说,问题只是我正在使用模拟器输入未保存为测试电话号码的电话(Firebase-> 身份验证-> 登录方法-> 电话-> 并在此处添加测试电话号码

Generate SHA-1 certificate prefer this link SHA-1 fingerprint of keystore certificate生成 SHA-1 证书首选此链接密钥库证书的 SHA-1 指纹
在此处输入图片说明

after open your firebase console and add this SHA-1 Key here.打开 Firebase 控制台并在此处添加此 SHA-1 密钥后。

I was also facing the similar issue in react-native build as show in the below picture.我在 react-native 构建中也遇到了类似的问题,如下图所示。 I solved the problem by following the below mentioned steps.我按照下面提到的步骤解决了这个问题。

在此处输入图片说明

According to @adirzoari open your react native project into android studio and then:根据@adirzoari,将您的本机项目打开到 android studio 中,然后:

  1. Run your project.运行你的项目。
  2. Click on Gradle menu.单击 Gradle 菜单。
  3. Expand Gradle Tasks tree.展开 Gradle 任务树。
  4. Double click on android -> signingReport and you'll see the result双击android->signingReport,你会看到结果

For Android studio 2.2 - result will be available under Run console but use highlighted toggle button.对于 Android studio 2.2 - 结果将在运行控制台下可用,但使用突出显示的切换按钮。

enter image description here How to fix please verify that the correct package name and sha1 are configured in the firebase console:在此处输入图像描述如何修复请验证是否在 firebase 控制台中配置了正确的包名称和 sha1:

  1. Make sure add SHA in firebase in your app Klik Settings -> Project Settings -> General -> Add Fingerprint (SHA 1 in your app) -> Save确保在您的应用中的 firebase 中添加 SHA Klik Settings -> Project Settings -> General -> Add Fingerprint (SHA 1 in your app) -> Save

  2. And then Klik Authentication -> Sign-in method -> Phone -> Phone number testing (optional) -> Save然后点击身份验证 -> 登录方法 -> 电话 -> 电话号码测试(可选) -> 保存

  • Provide the phone number you want to test, for example: +1 650-555-3434提供您要测试的电话号码,例如:+1 650-555-3434
  • Provide the 6-digit verification code for that specific number, for example: 654321 enter image description here提供该特定号码的 6 位验证码,例如:654321在此处输入图片说明
  1. Whoolaaaaa its work for me "Code been sent" in emulator enter image description here Whoolaaaaa它对我的工作在模拟器中“代码已发送”在此处输入图像描述

Add SHA-1 without SHA-1 mentioning in it.添加 SHA-1 而不在其中提及 SHA-1。 Like you have SHA-1 as :就像你有 SHA-1 一样:

SHA1: 6G:49:58:57:A2:5C:2R:95:7D:32:19:4A:69:05:14:F2:31:0D:72:0A SHA1: 6G:49:58:57:A2:5C:2R:95:7D:32:19:4A:69:05:14:F2:31:0D:72:0A

Add only this to firebase Project settings仅将此添加到 firebase 项目设置

6G:49:58:57:A2:5C:2R:95:7D:32:19:4A:69:05:14:F2:31:0D:72:0A 6G:49:58:57:A2:5C:2R:95:7D:32:19:4A:69:05:14:F2:31:0D:72:0A

For more info欲了解更多信息

You can generate SHA keys from gradle command您可以从 gradle 命令生成 SHA 密钥

./gradlew signingReport ./gradlew 签名报告

Go to your firebase console -> Authentication -> SIGN-IN Method -> Phone .转到您的 firebase 控制台 -> Authentication -> SIGN-IN Method -> Phone 。 Add the random numbers with verification code to enter image description here "Phone numbers for testing (optional)" field.添加带有验证码的随机数字以在此处“测试电话号码(可选)”字段中输入图像描述

Problem Solve -->问题解决 --> 在此处输入图像描述 enable phone provider and sh1 and sh256 from project setting and also add your country code in a phone number while sending phone number for authentication从项目设置中启用电话提供商和 sh1 和 sh256,并在发送电话号码进行身份验证时在电话号码中添加您的国家代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 此应用未被授权使用 Firebase 身份验证。请验证是否在 Firebase 控制台中配置了正确的 package 名称和 SHA-1 - 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 将 iOS 应用程序连接到 Firebase 身份验证模拟器 - Connect iOS app to Firebase Authentication Emulator 无法将管理员 SDK 连接到 firebase 身份验证模拟器 - Cannot connect Admin SDK to firebase authentication emulator 具有 firebase 身份验证的应用程序不断停止 - App with firebase authentication keeps stopping 如何使用Firebase模拟器写入Firestore、Storage? - How to use Firebase Emulator to write to Firestore, Storage? 将 Firebase 电话身份验证与协程一起使用 - Use Firebase Phone Authentication with Coroutines 如何在Flutter中使用Firebase模拟器演示工程? - How to use a Firebase emulator demo project in Flutter? 没有模拟器怎么用firebase? - How can I use firebase without the emulator? 如何让firebase function模拟器使用生产firebase存储桶 - How to let firebase function emulator use production firebase storage bucket 将 Firebase-functions-emulator 与远程 firebase 服务一起使用 - Use Firebase-functions-emulator with remote firebase services
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM