【发布时间】:2021-07-02 03:02:25
【问题描述】:
我在使用 Expo 管理的 React Native 应用程序中实施 Google Auth 时遇到问题。 当我尝试登录时,响应不包含 IdToken 或用户信息,我不明白为什么......
这是我的代码:
import * as Google from 'expo-auth-session/providers/google';
const [request1, response1, promptAsync1] = Google.useAuthRequest({
expoClientId: 'my-expo-id',
iosClientId: 'my-ios-id',
});
React.useEffect(() => {
if (response1?.type === 'success') {
const { authentication } = response1;
}
}, [response]);
console.log('reponse', response1)
return (
<View>
<TouchableOpacity onPress={() => promptAsync1()}>
<Text style={styles.connexionText}>Connect with Google</Text>
</TouchableOpacity>
</View>
)
这是回复:
reponse Object {
"authentication": TokenResponse {
"accessToken": "ya29.a0AfH6SMAEdPx5RcQP57rtdr4gV8GxFD1VSLAjovOce5X1yP-a2S6inLcSHF3KlxqmbKt0Cl6Catuyuua9Jz0rtV5psUUqWWX_QT32rXJwt9LTQywQaOzyy4cwspbOLm6W063w27f7NRiizC9RBg69-Yh09OhN",
"expiresIn": "3599",
** "idToken": undefined, **
"issuedAt": 1617701320,
** "refreshToken": undefined, **
"scope": "email profile https://www.googleapis.com/auth/userinfo.profile openid https://www.googleapis.com/auth/userinfo.email",
"state": "RwgjNwizdQ",
"tokenType": "Bearer",
},
"error": null,
"errorCode": null,
"params": Object {
"access_token": "ya29.a0AfH6SMAEdPx5RcQP57rtdr4gV8GxFD1VSLAjovOce5X1yP-a2S6inLcSHF3KlxqmbKt0Cl6Catuyuua9Jz0rtV5psUUqWWX_QT32rXJwt9LTQywQaOzyy4cwspbOLm6W063w27f7NRiizC9RBg69-Yh09OhN",
"authuser": "0",
"exp://172.20.10.3:19000/--/expo-auth-session": "",
"expires_in": "3599",
"prompt": "none",
"scope": "email profile https://www.googleapis.com/auth/userinfo.profile openid https://www.googleapis.com/auth/userinfo.email",
"state": "RwgjNwizdQ",
"token_type": "Bearer",
},
"type": "success",
"url": "exp://172.20.10.3:19000/--/expo-auth-session#state=RwgjNwizdQ&access_token=ya29.a0AfH6SMAEdPx5RcQP57rtdr4gV8GxFD1VSLAjovOce5X1yP-a2S6inLcSHF3KlxqmbKt0Cl6Catuyuua9Jz0rtV5psUUqWWX
_QT32rXJwt9LTQywQaOzyy4cwspbOLm6W063w27f7NRiizC9RBg69-Yh09OhN&token_type=Bearer&expires_in=3599&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20openid%20https:/
/www.googleapis.com/auth/userinfo.email&authuser=0&prompt=none",
}
非常感谢您的帮助!
【问题讨论】:
-
是的,最糟糕的是,使用谷歌进行身份验证的旧方法确实提供了 idToken——你不能将它用于网络:/。如果您只是将您的应用范围缩小到仅适用于 android 和 ios,我建议您使用较旧的方法 (expo-google-app-auth)。如果我找到解决办法,我会在这里报告。
标签: react-native expo google-authentication