【发布时间】:2017-12-06 02:49:00
【问题描述】:
我的网络应用允许使用 Google 帐户注册/登录。我正在使用以下代码从 Google 获取用户信息:
var scopes = ['profile', 'email'];
var url = oauth2Client.generateAuthUrl({ access_type: 'offline', scope: scopes });
router.route('/authorize').post((req, res) => {
code = req.body.code;
oauth2Client.getToken(code, (err, tokens) => {
if (err) return // error handler
oauth2Client.verifyIdToken(tokens.id_token, clientId, (err, login) => {
if (err) return // error handler
console.log(login.getPayload()); // this gives me the JSON object below
});
});
});
我尝试添加不同的范围,但我总是得到相同的信息,其中不包括用户的真实姓名:
{ azp: 'stuffblahblah',
aud: 'stuffblahblah',
sub: 'google-id-here',
email: 'email@address.com',
email_verified: true,
at_hash: 'some-hash',
iss: 'accounts.google.com',
iat: 1234567890,
exp: 1234567890 }
【问题讨论】:
标签: javascript node.js authentication authorization google-signin