我的应用有一个基于 Firebase 的 Google 登录。我正在尝试获取访问令牌但未定义。我正在获取 idToken 但我需要 AccessToken 并刷新令牌。我需要帮助
这是我的代码:
GoogleSignin.configure({
scopes: ['profile', 'email','https://www.googleapis.com/auth/calendar'], //adding calender scope
webClientId: '863338747777-9bshdpj951ga8nik9tbtua52ji0h06k4.apps.googleusercontent.com',
offlineAccess: true,
forceCodeForRefreshToken: true,
});
const onGoogleButtonPress = async()=> {
try
{
await GoogleSignin.hasPlayServices();
const {accessToken, idToken} = await GoogleSignin.signIn();
const credential = auth.GoogleAuthProvider.credential(
idToken,
accessToken,
);
await auth().signInWithCredential(credential);
console.log('IDToken: ',idToken,accessToken)
console.log('AccessToken: ',accessToken)
}
catch(error)
{
console.log(error)
}
finally{
setLoggedIn(true)
}
}`
答案 0 :(得分:0)
Prabhakar 我希望这个链接对他有帮助。
https://www.freecodecamp.org/news/google-login-with-react-native-and-firebase/
谢谢
答案 1 :(得分:0)
我为自己的问题找到了解决方案。我使用的是旧版的 React Native google 登录库。新的库是 React Native 登录 google。新包也返回了 accessToken。所以要获取刷新令牌,我们需要使用 api This is the Link for that .
我们需要几个标题 Take a look at them
您将在登录时从 googleSignin 函数获取 serverAuthCode。
const UserInfo = await GoogleSignin.signIn();
控制台记录 UserInfo 以获取 serverAuthCode 、AccessToken 和 Refresh Token