我正在尝试使用 Expo 在 React-Native 上设置本机 Google 身份验证谷歌登录 https://docs.expo.io/versions/v32.0.0/sdk/google-sign-in/API,但无法获取授权 Google 用户的 idToken。
它有 accessToken 作为响应,但没有 idToken。
所以我使用一些简单的代码,例如
const result = await GoogleSignIn.initAsync({
isOfflineEnabled: true,
isPromptEnabled: true,
//webClientId: 'webClientId',
clientId // now testing only on Android, so this is irrelevant
});
console.log(result);
响应示例:
Object {
"auth": Object {
"accessToken": "accessToken",
"accessTokenExpirationDate": null,
"idToken": null, // here is the problem!
"refreshToken": null,
},
"displayName": "Danila Tsvetkov",
"email": "email@email",
"firstName": "Danila",
"hostedDomain": undefined,
"lastName": "Tsvetkov",
"serverAuthCode": null,
"uid": "uid",
}
同时Google https://docs.expo.io/versions/v32.0.0/sdk/google/OAuth API不仅返回accessToken,还返回idToken和refreshToken。
其他一切都工作正常,例如授权和登录流程。
也许问题出在 serverAuthCode 上?
尝试放置 webClientId,api 停止正常工作。将 SHA1 添加到 google-services (更多信息 https://github.com/react-native-community/react-native-google-signin/issues/224),没有帮助。更改其他参数(例如“isOfflineEnabled”)也没有多大作用。