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

编程入门 行业动态 更新时间:2024-10-09 22:20:32

如何从<a href=https://www.elefans.com/category/jswz/34/1771386.html style=护照回调中提取其他API范围?"/>

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

我想通过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: ['.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检索信息,或者如何完全检索该信息。

回答如下:

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

更多推荐

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

本文发布于:2024-05-07 09:26:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1755598.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:护照   回调   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!