我正在尝试使用重定向方法使用 Google 实现登录。我正在关注此链接 我的代码如下所示
<script src="https://apis.google.com/js/platform.js?onload=startGoogleApp" async defer></script>
<script>
var startGoogleApp = function () {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: '@googleClientId',
ux_mode: 'redirect',
redirect_uri: '@googleRedirectUri',
fetch_basic_profile: true
});
auth2.signIn();
});
}
</script>
但问题在于 Google 的 id_token 没有名称,即使我已经通过了fetch_basic_profile: true
,我也尝试过使用scope: 'profile'
.
我想获取姓名和电子邮件。不知道我在这里做错了什么。我想要它作为令牌的一部分,因为它在我正在关注的文档中提到。我不想通过额外的 api 调用来获取名称。可能吗?id_token 看起来像这样
{
"iss": "accounts.google.com",
"azp": "*********",
"aud": "***********",
"sub": "*********",
"hd": "***.com",
"email": "*****@***.com",
"email_verified": true,
"iat": 1599717107,
"exp": 1599720707,
"jti": "*******"
}