【问题标题】:Flutter Firebase phone authentication problemFlutter Firebase 手机认证问题
【发布时间】:2021-04-04 16:54:58
【问题描述】:

我试图用手机登录。每次我输入手机号码时,它都会显示这些错误消息并退出应用程序。我使用了来自https://firebase.flutter.dev/docs/auth/phone 文档的代码。代码与文档几乎相同。

E/zzf     (31149): Problem retrieving SafetyNet Token: 7:
I/Timeline(31149): Timeline: Activity_launch_request time:483815514
W/ActivityThread(31149): SCHED: com.example.newdevice/.MainActivity [85, r=578ms, a=96ms, w=57017ms]
W/ActivityThread(31149): handleWindowVisibility: no activity for token android.os.BinderProxy@dc5d811
D/ForceDarkHelper(31149): updateByCheckExcludeList: pkg: com.example.newdevice activity: com.google.firebase.auth.internal.RecaptchaActivity@5ed566f
I/chatty  (31149): uid=10315(com.example.newdevice) identical 1 line
D/ForceDarkHelper(31149): updateByCheckExcludeList: pkg: com.example.newdevice activity: com.google.firebase.auth.internal.RecaptchaActivity@5ed566f
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
......More error message.......

我正在为 Java/Flutter/Firebase sdk 等所有内容使用更新版本。我还在 Firebase 应用程序中添加了 SHA1 密钥并启用了电话身份验证。 我还尝试了物理设备和虚拟设备。但每次都是同样的问题。

应用级 build.gradel 文件中的依赖项

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:26.2.0')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'androidx.browser:browser:1.3.0'
    implementation 'com.android.support:multidex:1.0.3'
}

用于移动验证的 Flutter 代码部分:

                    FirebaseAuth _auth = FirebaseAuth.instance;
                    await _auth.verifyPhoneNumber(
                        phoneNumber: mobileController.text,
                        verificationCompleted:
                            (PhoneAuthCredential credential) {
                          print(credential);
                        },
                        verificationFailed: (FirebaseAuthException error) {
                          print(error);
                        },
                        codeSent:
                            (String verificationId, int resendToken) async {
                              print('Your otp sent');
                              String smsCode = '123456';

                              PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.credential(verificationId: verificationId, smsCode: smsCode);

                              // Sign the user in (or link) with the credential
                              await _auth.signInWithCredential(phoneAuthCredential);
                            },
                        timeout: const Duration(seconds: 120),
                        codeAutoRetrievalTimeout: (String verificationId) {
                          print(verificationId);
                        }
                      );

我在这里糟透了。几乎尽我所能。

【问题讨论】:

  • 请编辑问题以显示所有相关代码,即使它与其他代码“几乎相同”。请务必说明该代码无法按您预期的方式运行的原因。
  • 感谢您的 cmets。现在添加了 Flutter 代码部分。 “codeSent”函数从未执行。

标签: android flutter dart firebase-authentication


【解决方案1】:

试试这些步骤。

  1. 当然,为您的项目启用Android Device Verification(API)
  2. 您需要添加 SHA1 和 SHA256 哈希键。 (注意:不是调试密钥,您需要添加发布构建密钥。
  3. 要创建这些发布版本密钥 - 请查看此网站 (https://www.youtube.com/watch?v=S7yyA6SFnjE)
  4. 将这些创建的发布构建密钥添加到您的 firebase 项目中,然后将您新下载的 json 文件导入到您的项目中。

【讨论】:

    【解决方案2】:

    我通过这些步骤克服了这个问题-

    1. 在 Google Cloud 控制台中,为您的项目启用 Android DeviceCheck API。 (**注意:选择您的 Firebase 项目并启用它)

    2. 为您的应用获取SHA-256 fingerprint

    3. 转到 Firebase 控制台的设置页面,选择您的项目并为您的应用设置 SHA-256 指纹。

    重新运行应用程序。该解决方案对我有用。希望它也对你有用。

    【讨论】:

      猜你喜欢
      • 2020-07-21
      • 2021-11-16
      • 2020-12-04
      • 2021-12-09
      • 2021-04-21
      • 2020-11-27
      • 1970-01-01
      • 2021-05-28
      • 2020-01-23
      相关资源
      最近更新 更多