固定:所以我从react-native-google-signin
收到的令牌是不够的,我还应该安装firebase并使用它,如所接受的答案所示,然后使用来自firebase
的令牌。
原文:
我正在使用react-native-google-signin
登录用户到一个应用程序,在登录时,我得到一个jwt令牌。
在firebase上,我有以下https云函数:
exports.verify = functions.https.onRequest((req, res) => {
const tokenId = req.get('Authorization').split('Bearer ')[1];
return admin.auth().verifyIdToken(tokenId)
.then((decoded) => res.status(200).send(decoded))
.catch((err) => res.status(401).send(err));
});
当我从react-native-google-signin
发送令牌进行验证时,我会得到以下响应:
{
"code": "auth/argument-error",
"message": "Firebase ID token has incorrect \"aud\" (audience) claim. Expected \"my-project\" but got \"1232345345-sdfsdfsdfsdf.apps.googleusercontent.com\". Make sure the ID token comes from the same Firebase project as the service account used to authenticate this SDK. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token."
}
在这种情况下,aud是“my”身份验证方法中来自firebase google签名的webclient。我该如何解决这个问题,因为它是火焰基,给我的是令牌,它是拒绝令牌的火力基地.
发布于 2019-08-29 03:36:01
首先,确保用于承载云功能的Firebase项目与React应用程序中使用的Firebase项目相同。
其次,确保在React应用程序中检索Firebase用户,然后调用getIdToken
。
示例
import { GoogleSignin } from 'react-native-google-signin';
onLoginOrRegister = () => {
GoogleSignin.signIn()
.then((data) => {
const credential = firebase.auth.GoogleAuthProvider.credential(data.idToken, data.accessToken);
return firebase.auth().signInWithCredential(credential);
})
.then((user) => {
// ** Now that the user is signed in, you can get the ID Token. **
user.getIdToken(/* forceRefresh */ true).then(function(idToken) ...
})
.catch((error) => {
const { code, message } = error;
});
}
firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken)
发布于 2021-10-15 11:42:05
我认为您是在Google SignIn之后使用令牌,其AUD与1232345345-sdfsdfsdfsdf.apps.googleusercontent.com
类似。
调用signInWithCredential
后,需要使用返回的令牌
谁的澳元将是您的project_id
https://stackoverflow.com/questions/57691452
复制相似问题