我正在尝试在我的 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.
以下是我为使它正常工作所遵循的过程:
转到 GCP Console > 选择旧项目 > API 和服务 > 凭据
创建凭据 > OAuth 客户端 ID
选择网络应用
- 输入姓名
- 将 Javascript 来源和授权重定向 URL 留空
复制客户端id
打开 firebase 控制台
- 转到身份验证 > 登录方法 > google
- 将新的客户端 ID 列入白名单 > 添加 > 保存
- 返回设置 > 将 firebase 添加到您的 Android 应用
- 添加你的android包名
- 将签名证书留空
- 点击注册应用
- 下载并打开 google-services.json
在 oauth_client 中,您的应用程序中的每个 oauth 客户端 ID 都会有一个条目(仅供引用,这些可以在 GCP 控制台上的 API 和服务 > 凭据下看到)。
删除整个
oauth_client
标记并替换为"oauth_client": [ { "client_id": "<your_new_client_id>", "client_type": 3 } ],
如果您需要任何其他 oauth 客户端,请确保列入白名单的客户端位于顶部,因为这似乎是默认设置。保存文件并复制到您的 Android 应用模块中。
确保您具有以下依赖项:
- 项目根目录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'
构建并运行您的项目
如果您遇到此错误(没有更多详细信息):
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/