简体   繁体   English

获取 Firebase Phone Auth OTP 时出错

[英]Error while geting Firebase Phone Auth OTP

I am trying to implement Firebase Phone Verification.我正在尝试实施 Firebase 电话验证。 I have enabled phone verification on firebase console.我在 firebase 控制台上启用了电话验证。 I have generated keystore and added the SHA signatures to the console.我已生成密钥库并将 SHA 签名添加到控制台。

dependencies:依赖项:

dependencies {
    def multidex_version = "2.0.1"
    implementation platform('com.google.firebase:firebase-bom:26.0.0')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics'
    implementation "androidx.multidex:multidex:$multidex_version"
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-core'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'

}

phone_verification.dart phone_verification.dart

                await FirebaseAuth.instance.verifyPhoneNumber(
                  phoneNumber: '+1234567890',

                  verificationCompleted: (PhoneAuthCredential credential) {
                    print('verificationCompleted');
                    
                  },
                  verificationFailed: (FirebaseAuthException e) {
                    print('verificationFailed');
                    if (e.code == 'invalid-phone-number') {
                      print('The provided phone number is not valid.');
                    }
                    else {
                      print('Some error occoured: $e');
                    }
                  },
                  codeSent: (String verificationId, int resendToken) async {
                    print('codeSent');

                    // Update the UI - wait for the user to enter the SMS code
                    String smsCode = '123456';

                    // Create a PhoneAuthCredential with the code
                    PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.credential(verificationId: verificationId, smsCode: smsCode);
                  
                  },
                  timeout: const Duration(seconds: 60),
                  codeAutoRetrievalTimeout: (String verificationId) {
                    print("Timeout: $verificationId");
                  },
                );

When the above block is executed following error is received.执行上述块时,会收到以下错误。 Console Output:控制台 Output:

E/FirebaseAuth: [GetAuthDomainTask] Error getting project config. Failed with {
      "error": {
        "code": 400,
        "message": "INVALID_CERT_HASH",
        "errors": [
          {
            "message": "INVALID_CERT_HASH",
            "domain": "global",
            "reason": "invalid"
          }
        ]
      }
    }
     400
V/FA: Recording user engagement, ms: 1165
E/zza: Failed to get reCAPTCHA token - calling backend without app verification

@CubeRootX and @user13864571 @CubeRootX 和 @user13864571

Your problem related to SHA1 and SHA256 keys.您的问题与 SHA1 和 SHA256 密钥有关。 You have to add them to authenticate your certs.您必须添加它们以验证您的证书。

Goto

  • Firebase Console of your project您项目的 Firebase 控制台
  • Authentication验证
  • Project Setting (From Setting button near Project Overview)项目设置(从项目概览附近的设置按钮)
  • Add fingerprint添加指纹
  • Add SHA-1 and SHA-256 values of your keystore.添加密钥库的 SHA-1 和 SHA-256 值。

You can get keystores from gradle like this.您可以像这样从 gradle 获取密钥库。

./gradlew signingReport ./gradlew 签名报告

Read this for more information: https://firebase.google.com/docs/auth/android/phone-auth#enable-app-verification阅读更多信息: https : //firebase.google.com/docs/auth/android/phone-auth#enable-app-verification

在 Firebase 控制台中的身份验证下启用电话选项

Error 400 means bad request, it can be due to any of the following three reasons:-错误 400 表示请求错误,可能是由于以下三个原因之一:-

  1. Check if phone authentication option is enabled in firebase console or not.检查是否在 firebase 控制台中启用了电话身份验证选项。 Enable it.启用它。
  2. Check if Android Device Check API is enabled in Google cloud console or not.检查是否在Google 云控制台中启用了 Android Device Check API。 Enable it.启用它。
  3. Check if SHA-1 and SHA-256 are added to your firebase project or not.检查 SHA-1 和 SHA-256 是否已添加到您的 Firebase 项目中。 Add it as follows:添加如下:

Open your project in firebase console -> Go to project setting -> Click on add fingerprint (at the bottom of the page) -> Add the SHA-1 and SHA-256 values there.在 firebase 控制台中打开您的项目 -> 转到项目设置 -> 单击添加指纹(在页面底部)-> 在那里添加 SHA-1 和 SHA-256 值。 Image for reference图片供参考

You can get the SHA values of your android studio project as follows:-您可以按如下方式获取 android studio 项目的 SHA 值:-

Click on gradle on top right side -> task -> android -> signingReport -> Get the SHA values at the bottom after running signingReort Image for reference点击右上角的gradle->任务->android->signingReport->运行signingReort后获取底部的SHA值,供参考

Follow the documentation if issue in not resolved.如果问题未解决,请按照文档进行操作

I have been stuck here for a week only to find a key I was using was restricted to another app and was therefore failing when trying to use it in my app.我被困在这里一个星期才发现我使用的密钥仅限于另一个应用程序,因此在我的应用程序中尝试使用它时失败。 So I first removed the restriction in the credentials tab in Android device verification and everything went back to normal所以我首先取消了Android设备验证中凭据选项卡中的限制,一切都恢复了正常

We need to add one extra step to @Anat Bharti Answer: Enable GCS Device Verification API on Your Project我们需要向@Anat Bharti 回答添加一个额外的步骤:在您的项目上启用 GCS 设备验证 API

Enable GCS Device Verification API on Your Project.在您的项目上启用 GCS 设备验证 API。 That solves Everything, You not even asked to Verify capcha on your Physical device.这解决了一切,你甚至没有要求在你的物理设备上验证验证码。

暂无
暂无

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

相关问题 Firebase 手机身份验证中的 OTP 在 playstore 上传时未收到,但直接在手机上安装 apk 时工作正常 - OTP in Firebase phone auth is not receiving when uploaded on playstore, but works fine when apk is installed on phone directly Firebase 电话验证错误“APP_NOT_VERIFIED” - Firebase phone auth error "APP_NOT_VERIFIED" 无法使用 ReactJS 中的 firebase 身份验证重新发送 OTP - Not able to resend OTP using firebase auth in ReactJS OTP [firebase_auth/未知] null - OTP [firebase_auth/unknown] null Firebase 电话验证仅在发布模式下不启动 OTP,但即使在为发布模式添加 sha1 后也可以在调试模式下工作 - Firebase phone auth not initiating OTP only in release mode but works on Debug mode even after added sha1 for release mode firebase 电话号码认证 - firebase auth with phone number Firebase 电话认证只发送 OTP 用于测试电话号码 - Firebase Phone authentication only sending OTP For Testing Phone Numbers Firebase fetchSignInMethodsForEmail 不提供电话身份验证 - Firebase fetchSignInMethodsForEmail not providing phone auth flutter firebase 电话身份验证错误 safety.net 令牌已通过,但在 firebase 控制台中未注册匹配的 sha-256 - flutter firebase phone auth error a safety net token was passed but no matching sha-256 was registered in the firebase console 构建一个使用 firebase_auth 的 flutter 应用程序,它在手机上运行良好,但在我在 web 上运行时出错,说 http_parser 路径丢失 - Building a flutter app that uses firebase_auth which runs fine on phone but gives error while i run on web, says http_parser path missing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM