android - "Developer error: this application is misconfigured"Google 使用列入白名单的客户端 ID 在 firebase 上登录

标签 android firebase google-app-engine firebase-authentication

我正在尝试在我的 Android 应用程序上迁移到 firebase 身份验证。包名称和 SHA1 当前与一个旧的应用程序引擎项目相关联(我不想升级到 firebase),因此我无法将 SHA1 指纹添加到我的新 firebase 项目中。 App Engine 项目目前正在生产中,因此我无法删除 Android 客户端 ID 或删除该项目。这里的文档 https://support.google.com/firebase/answer/6401008?authuser=0说我应该能够将旧应用引擎项目的客户端 ID 列入白名单。但是,当我这样做然后尝试使用 firebase 身份验证通过 google 登录应用程序时,我收到以下错误 “开发人员错误:此应用程序配置错误。在 Firebase 控制台中检查您的 SHA1 和包名称。”

我也试过这里的说明https://firebase.googleblog.com/2016/12/working-with-multiple-firebase-projects-in-an-android-app.html这涉及将 GoogleSignInOptions 对象传递到 AuthUI 构建器中,其中包含来自适当项目的 Web 客户端 ID,如下所示:

private void StartLoginActivity() {

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken("<my-client-id>.apps.googleusercontent.com")
            .requestEmail()
            .build();

    List<AuthUI.IdpConfig> providers = Arrays.asList(
            new AuthUI.IdpConfig.EmailBuilder().build(),
            new AuthUI.IdpConfig.GoogleBuilder().setSignInOptions(gso).build());

    startActivityForResult(
            AuthUI.getInstance()
                    .createSignInIntentBuilder()
                    .setAvailableProviders(providers)
                    .build(),
            RC_SIGN_IN);
}

但是当我这样做时,我得到了错误java.lang.IllegalArgumentException: two different server client ids provided

所以我的问题是,当 SHA1 与现有 GCP 项目相关联时,如何配置我的 firebase 项目以启用身份验证?

最佳答案

我从 firebase 支持人员那里得到了以下回复,并且能够让它正常工作:

Google sign in with FirebaseUI is configured through the google-services.json >file. The issue is that if you are using an OAuth client ID from a different >project, the default_web_client_id will be configured incorrectly. It will be >pointing to the auto generated web client id of your new Firebase project; we >don't want this.

In step 1 of https://developers.google.com/identity/sign-in/android/backend->auth, we call #requestIdToken(getString(R.string.server_client_id)). In >firebaseUI, this is also done and this resource is 'default_web_client_id' - >generated by google-services.json. This needs to be changed.

So to resolve the issue you need to use the web OAuth client ID from project >#1, you can do this by either:

Changing the google-services.json file - you'd need to change the client_id >fields to the correct web client id from project #1 You also need to whitelist (Auth > Sign In Providers > Google) the web client >OAuth from project#1 to project#2

Not use google-services.json so you can set the default_web_client_id himself. We made a guide for this, see here.

以下是我为使它正常工作所遵循的过程:

  1. 转到 GCP Console > 选择旧项目 > API 和服务 > 凭据

  2. 创建凭据 > OAuth 客户端 ID

  3. 选择网络应用

    • 输入姓名
    • 将 Javascript 来源和授权重定向 URL 留空
  4. 复制客户端id

  5. 打开 firebase 控制台

  6. 转到身份验证 > 登录方法 > google
  7. 将新的客户端 ID 列入白名单 > 添加 > 保存
  8. 返回设置 > 将 firebase 添加到您的 Android 应用
    • 添加你的android包名
    • 将签名证书留空
  9. 点击注册应用
  10. 下载并打开 google-services.json
  11. 在 oauth_client 中,您的应用程序中的每个 oauth 客户端 ID 都会有一个条目(仅供引用,这些可以在 GCP 控制台上的 API 和服务 > 凭据下看到)。

  12. 删除整个oauth_client标记并替换为 "oauth_client": [ { "client_id": "<your_new_client_id>", "client_type": 3 } ], 如果您需要任何其他 oauth 客户端,请确保列入白名单的客户端位于顶部,因为这似乎是默认设置。

  13. 保存文件并复制到您的 Android 应用模块中。

  14. 确保您具有以下依赖项:

    • 项目根目录build.gradle
    • 类路径 'com.google.gms:google-services:4.0.0'
    • 应用模块build.gradle
    • 编译“com.google.firebase:firebase-core:16.0.0”
    • 编译'com.firebaseui:firebase-ui-auth:4.0.0'
  15. 构建并运行您的项目

如果您遇到此错误(没有更多详细信息): BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?alt=proto&key=AIzaSyBJL6EO8vMEJpyWUCAKP8ZgH4LYR0Hrwpk

检查您的 gradle 依赖项是否设置为上述(或更高)版本

如果你得到这个错误: com.google.firebase.FirebaseException: An internal error has occurred. [ Invalid Idp Response:the Google id_token is not allowed to be used with this application. Its audience (OAuth 2.0 client ID) is <your-client-id>, which is not authorized to be used in the project with project_number: <your-project-number>. ]

尝试在 firebase 控制台上删除并重新添加列入白名单的客户端 ID。

关于android - "Developer error: this application is misconfigured"Google 使用列入白名单的客户端 ID 在 firebase 上登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50452779/

相关文章:

Swift 3.1 - .set Values For Keys 和 Firebase 无法检索用户

php - 在 Google App Engine 上运行 Wordpress 时出现数据库错误

google-app-engine - 在 app.yaml 上指定的环境变量,但未在 main.go 上获取

java - android:onClick 监听器,仅用于 XML 中的 onTouch

导入模块构建时出现 Android 错误,gradle - 找不到方法 instrumentTestCompile()

php - Google Firebase 通知在控制台上工作但不在 API 上工作

firebase - 我在Cloud Firestore交易中遇到异常

java - 在 Google App Engine 上建立 TLS v1.2 连接

android - 来自 Android 设备的节能视频流

android - 在 Google map fragment 中重新定位 MyLocation 按钮