在我的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."}}]
答案 0 :(得分:0)
在错误消息中添加网址=>例如。你的情况= 268165840544-097g31a3qhd0mm.apps.googleusercontent.com
下
身份验证>登录方法>谷歌
Firebase上的 Whitelist client IDs from external projects (optional)