firebase_auth/custom-token-mismatch 自定义token对应不同的受众

问题描述 投票:0回答:0

我有一个 Flutter 应用程序在生产中有很多用户,使用 Firebase 后端。我想通过谷歌云功能生成自定义令牌来向它添加 Firebase 身份验证。

我创建了另一个 Firebase 项目作为开发环境,并通过 NodeJS 云功能实现并测试了 Firebase 身份验证,一切都很好,现在我将云功能部署到生产环境。

我不在 NodeJS 中使用任何 API Google API 密钥,因为所有云功能都在 GCP 上自动进行身份验证。在 Flutter 中,我用正确的生产环境替换了开发环境

google-services.json
。我没有任何
GoogleService-Info
,我正在Android上测试。

main.dart
中,我像这样初始化我的应用程序

  if (Firebase.apps.isEmpty) {
    try {
      await Firebase.initializeApp(
        name: "foo",
        options: DefaultFirebaseOptions.currentPlatform,
      );
    } catch (e) {
      print("could not initialize firebase ${e}");
    }
  }

options: DefaultFirebaseOptions.currentPlatform
,是由 FlutterFire CLI 生成的文件,它包含生产应用程序凭据,这是我在进行开发环境测试时忘记更改的唯一文件,我忘记为开发创建新应用程序和更改
firebase_options.dart

中的值

现在发生的事情是,云函数正在正确生成令牌,但是每当我尝试在 Flutter 中通过此令牌登录时

await FirebaseAuth.instance.signInWithCustomToken(firebase_token);

我收到这个错误

flutter (14645): Authentication error [firebase_auth/custom-token- 
mismatch] The custom token corresponds to a different audience.

如何解决这个错误?我不能只创建新的 Firebase 应用程序,如果这是错误的根本原因,有两个原因

  1. 我无法删除现有的,因为现有的用户将无法使用该应用程序

  2. 我不能创建新的应用程序,因为需要Android包名,它被现有的应用程序使用。

所以我想要一个不需要打扰现有用户的解决方案。如果不存在这样的解决方案,那么我会尝试通过开发环境对生产用户进行身份验证并创建另一个开发环境

flutter firebase firebase-authentication firebase-admin
© www.soinside.com 2019 - 2024. All rights reserved.