如何从通行证回调中提取其他 API 范围?

Chr*_*ner 5 javascript node.js express passport.js passport-google-oauth2

我想通过策略获取使用 Passport.js 的用户的生日passport-google-oauth20。我从哪里获得这个额外范围的响应以及如何提取这些信息?

我在从用户那里提取个人资料和电子邮件方面取得了成功,但我尝试的所有其他范围似乎都找不到它返回的位置。我正在使用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)

    ...
  })
);
Run Code Online (Sandbox Code Playgroud)

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

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)
})
Run Code Online (Sandbox Code Playgroud)

我的 node 和 npm 版本目前是:

node --version
v8.12.0

npm --version
6.9.0
Run Code Online (Sandbox Code Playgroud)

我的软件包版本如下:

...
"express": "^4.16.4",
"passport": "^0.4.0",
"passport-google-oauth20": "^2.0.0",
...
Run Code Online (Sandbox Code Playgroud)

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