在我的 React Native Expo 应用程序中,我想使用 google 帐户对用户进行身份验证。所以我跟着Expo Google首先使用 google 正常登录,这是有效的,然后使用 idToken
和 accessToken
通过 firebase 进行身份验证。
signInWithGoogleAsync = async () => {
try {
const result = await Google.logInAsync({androidClientId: ***, iosClientId: ***, scopes: ["profile", "email"] });
if (result.type === "success") { // I get result object
const credential = firebase.auth.GoogleAuthProvider.credential( result.idToken, result.accessToken);
/* credential is and xf {} object */
firebase.auth().signInWithCredential(credential)
.then(user => {console.log( user);})
.catch(error => {console.log(error);});
return result.accessToken;
}
return { cancelled: true };
} catch (e) {
return { error: true };
}
};
但我收到以下错误:
[Error: {"error":{"errors":[{"domain":"global","reason":"invalid","message":"Invalid Idp Response: the Google id_token is not allowed to be used with this application. Its audience (OAuth 2.0 client ID) is 268165840544-097g31a3qhd0mm.apps.googleusercontent.com, which is not authorized to be used in the project with project_number: 747269174."}],"code":400,"message":"Invalid Idp Response: the Google id_token is not allowed to be used with this application. Its audience (OAuth 2.0 client ID) is 26816581eun236bp9vdb7b6r.apps.googleusercontent.com, which is not authorized to be used in the project with project_number: 747269174."}}]
最佳答案
在错误消息中添加 url => 例如。你的案例 = 268165840544-097g31a3qhd0mm.apps.googleusercontent.com
在
身份验证 > 登录方式 > Google
Firebase 上的外部项目白名单客户端 ID(可选)
关于firebase - Expo, Firebase, 使用谷歌登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49228826/