如何从护照回调中提取其他API范围?

问题描述 投票:4回答:1

我想通过passport-google-oauth20策略使用Passport.js来获得用户的生日。在哪里可以得到此额外范围的响应,以及如何提取此信息?

我已经成功地从用户那里提取了个人资料和电子邮件,但是我尝试的所有其他作用域似乎都找不到返回的位置。我正在使用Google Identity Platform中的某些范围(更具体地说,是我已经从Google Cloud Platform激活的People API),它们没有出现在Passport策略回调中(仅个人资料和电子邮件)。

这是我设置护照并检查退货的地方

passport.use(
  new GoogleStrategy(config, (accessToken, refreshToken, profile, done) => {
    console.log(profile);
    // outputs:
    // id: ...
    // displayName: ...
    // name: { ... }
    // emails: [ { ... } ]
    // photos: [ { ... } ]
    // _raw: ...
    // _json: ... (above info plus profile link and locale)

    ...
  })
);

在我的路线内,我声明了范围并重定向用户

router.get('/auth/google/', passport.authenticate('google', {
    scope: ['https://www.googleapis.com/auth/user.birthday.read', 'profile', 'email']
}));

router.get('/auth/google/redirect/', passport.authenticate('google'), (req, res) => {
  res.redirect('http://localhost:2000/profile/' + req.user.id)
})

我的节点和npm版本当前为:

node --version
v8.12.0

npm --version
6.9.0

我的软件包版本如下:

...
"express": "^4.16.4",
"passport": "^0.4.0",
"passport-google-oauth20": "^2.0.0",
...

据我了解,我应该能够使用Passport检索个人资料,电子邮件和openid以外的更多信息,并且我了解我需要获取要激活的范围的API。我不了解的是如何从回调函数中的该API检索信息,或者如何完全检索该信息。

javascript node.js express passport.js passport-google-oauth2
1个回答
0
投票

您能解决这个问题吗?我正在尝试访问“性别和生日”,但没有成功。

© www.soinside.com 2019 - 2024. All rights reserved.