Flutter firebase_auth 中的无效应用程序凭据/令牌不匹配

use*_*349 14 ios firebase-authentication flutter

我已经开始根据官方文档在 Flutter 中设置 Firebase 电话身份验证。不幸的是,无论我如何尝试,我都会FirebaseAuthException在方法verificationFailed的回调中得到verifyPhoneNumber以下值:

code: "invalid-app-credential"
credential: null
email: null
message: "Token mismatch"
phoneNumber: null
plugin: "firebase_auth"
stackTrace: null
tenantId: null
Run Code Online (Sandbox Code Playgroud)

我创建了一个简单的存储库来重现该问题:https ://github.com/peternagy1332/basic_phone_auth

  1. 我曾经flutterfire configure将应用程序添加到现有的 Firebase 项目并在那里创建 IOS 应用程序。
  2. 我已经添加firebase_core@2.1.1firebase_auth@4.1.1
  3. 我已在 Firebase 上启用了电话登录方法,并添加了 +44 7123 123 456 作为测试号码,代码为 000000
  4. 我添加了Push notificationBackground modes功能以及Background fetchRemote notifications选项。
  5. 我已将 the REVERSED_CLIENT_IDfrom添加GoogleService-Info.plistURL Scheme.
  6. 在 Apple Developer 页面上,我生成了一个新密钥并将Apple Push Notifications service (APNs) service其作为APNs Authentication KeyFirebase 上传。

官方文档的设置部分向我指出了文档。这表明可能需要对 Swift 代码进行额外的修改,但目前还不清楚。我是一名 Flutter 开发人员,而不是一名原生 IOS 开发人员,我认为我实际上不需要做所有这些。

小智 26

    \n
  1. 确保在 AppDelegate.swift 中设置 FirebaseApp.configure()
  2. \n
\n
override func application(\n    _ application: UIApplication,\n    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n    ) -> Bool {\n        FirebaseApp.configure() \n        GeneratedPluginRegistrant.register(with: self)\n        return super.application(application, didFinishLaunchingWithOptions: launchOptions)\n    }\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. 将 APNS 令牌类型设置为 AuthAPNSTokenType.unknown。实际的令牌类型将从 app\xe2\x80\x99s 捆绑包中的配置文件中检测到。
  2. \n
\n
    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {\n        let firebaseAuth = Auth.auth()\n        firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)\n    }\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. 在 Runner.entitlements 文件中将 aps-environment 值从“development”更改为“unknown”
  2. \n
\n

跑步者权利

\n

  • 您需要将“import Firebase”添加到“AppDelegate.swift” (3认同)
  • 确认修复也与 iOS 16 上的 React Native 相关。* (3认同)
  • 添加未知解决了我的问题。但是这里有什么未知数以及它将如何影响我的生产环境? (2认同)

shu*_*ter 12

在 Flutter 应用程序中,我遇到了firebase_auth/invalid-app-credential: Invalid token 错误。对我来说,改变游戏规则的是将其添加APNs auth key到 Firebase 中。为了做到这一点:

1 - 访问 Apple 开发者网站并创建 Apple 推送通知服务(APNs) key。然后下载它。

2 - 上传Firebase > Project Settings > Cloud Messaging > Apple app configurationAPNs 密钥。

  • 这是建议的答案。如果您启用了 Firebase 云消息传递,则必须添加 APN 密钥。否则,Firebase 服务将无法运行。 (2认同)