【问题标题】:Flutter + Firebase - Phone Authentication OTP IssueFlutter + Firebase - 电话身份验证 OTP 问题
【发布时间】:2021-06-27 08:58:13
【问题描述】:

我正在尝试通过发送 OTP 并要求用户在收到该 OTP 后输入该 OTP 来验证电话号码。基于以下代码的此功能在 iOS 模拟器上运行良好,但在 Android 上运行不正常。

verifyPhoneNumber() async {
    await auth.verifyPhoneNumber(
      phoneNumber: '+92${widget.phoneNumber}',
      verificationCompleted: (PhoneAuthCredential credential) async {
        await auth.currentUser.updatePhoneNumber(credential);
      },
      verificationFailed: (FirebaseAuthException e) {
        print(e.message);
      },
      codeSent: (String verificationId, int resendToken) {
        setState(() {
          _otpcode = verificationId;
        });
      },
      codeAutoRetrievalTimeout: (String verificationId) {
        setState(() {
          _otpcode = verificationId;
        });
      },
    );
  }

为了让它在 android 上运行,我在 Firebase 控制台中添加了 SHA1 和 SHA256。我还启用了 Android DeviceCheck API。

在 android 上,当我在文本字段中输入电话号码后按下一步时,它似乎试图打开浏览器进行重新验证,但没有出现任何内容,只是移动到下一个屏幕询问 OTP。所以我假设它正在做隐形的recaptcha。

调试控制台显示以下错误:

( 9044): SafetyNet Attestation fails basic integrity.
I/zzjy    ( 9044): Provider GmsCore_OpenSSL not available
W/System  ( 9044): Ignoring header X-Firebase-Locale because its value was null.
E/FirebaseAuth( 9044): [GetAuthDomainTask] Error getting project config. Failed with {
E/FirebaseAuth( 9044):   "error": {
E/FirebaseAuth( 9044):     "code": 400,
E/FirebaseAuth( 9044):     "message": "INVALID_CERT_HASH",
E/FirebaseAuth( 9044):     "errors": [
E/FirebaseAuth( 9044):       {
E/FirebaseAuth( 9044):         "message": "INVALID_CERT_HASH",
E/FirebaseAuth( 9044):         "domain": "global",
E/FirebaseAuth( 9044):         "reason": "invalid"
E/FirebaseAuth( 9044):       }
E/FirebaseAuth( 9044):     ]
E/FirebaseAuth( 9044):   }
E/FirebaseAuth( 9044): }
E/FirebaseAuth( 9044):  400
E/zzf     ( 9044): Failed to get reCAPTCHA token - calling backend without app verification
W/System  ( 9044): Ignoring header X-Firebase-Locale because its value was null.
E/FirebaseAuth( 9044): [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17093 null
I/flutter ( 9044): This request is missing a valid app identifier, meaning that neither SafetyNet checks nor reCAPTCHA checks succeeded. Please try again, or check the logcat for more details.

如上所述,相同的代码在 iOS 上运行良好,但出于某些奇怪的原因,在 Android 上却不行。请让我知道我可能会错过什么。谢谢。

【问题讨论】:

    标签: firebase flutter firebase-authentication


    【解决方案1】:

    firebase otp 在模拟器上不起作用,通过构建 apk 在真实设备上尝试,或者从 firebase 控制台为您定义的数字提供静态 otp 代码,然后在模拟器上尝试。

    【讨论】:

      【解决方案2】:

      您需要包含依赖项androidx.browser:browser 才能使其在模拟器上运行

      SHA256 密钥和安卓设备验证 API 用于真实设备通过 Safetynet 检查。

      【讨论】:

        猜你喜欢
        • 2021-05-03
        • 2020-01-23
        • 2021-06-07
        • 2021-06-10
        • 1970-01-01
        • 2019-12-01
        • 1970-01-01
        • 2020-07-22
        • 1970-01-01
        相关资源
        最近更新 更多