expo-auth-session/providers/google Google.useAuthRequest [英] expo-auth-session/providers/google Google.useAuthRequest
问题描述
我在使用 Expo 管理的 React Native 应用程序中实施 Google Auth 时遇到问题.当我尝试登录时,响应不包含 IdToken 或用户信息,我不明白为什么......
I have a problem with the implementation of Google Auth within a React Native app managed with Expo. When I try to login, the response does not contain an IdToken or the information of the user and I don't understand why...
这是我的代码:
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,那么它是可能的.你需要像这样修改你的代码:
So it's possible to get the idToken if you that's all you are looking for. You need to modify your code like this:
const [request, response, promptAsync] = Google.useAuthRequest({
*responseType: "id_token",*
expoClientId: 'my-expo-id',
iosClientId: 'my-ios-id',
});
您还必须访问参数";密钥而不是身份验证",这将主要显示为空:).对我来说它至少有效,因为其余的信息是无用的.HTH!
You will also have to access the "params" key rather than "authentication," which will show mostly null :). For me it works at least since the rest of the information was useless. HTH!
我意识到我需要获取访问令牌才能在我的应用程序中使用谷歌驱动器,因此现在我需要两个令牌并在此处提交错误报告 https://github.com/expo/expo/issues/12808 尝试解决这个问题.
I realized that I need to get an Access Token to use google drive in my app, and thus now I need both tokens and submitted a bug report here https://github.com/expo/expo/issues/12808 to try to get this resolved.
这篇关于expo-auth-session/providers/google Google.useAuthRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!