javascript - 如何从护照回调中提取其他 API 范围?
问题描述
我想通过passport-google-oauth20
策略获取使用 Passport.js 的用户的生日。我从哪里得到这个额外范围的响应以及如何提取这些信息?
我在从用户那里提取个人资料和电子邮件方面取得了成功,但我尝试的所有其他范围似乎都找不到它返回的位置。我正在使用Google Identity Platform中的一些范围(更具体地说,是 People API,我已经从 Google Cloud Platform 激活了它)并且它们没有出现在 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)
})
我的 node 和 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 检索信息或如何检索该信息。
解决方案
推荐阅读
- angular - “找不到模块:错误:无法解决”错误
- node.js - 未从 SDK 中找到云功能,但可通过 HTTPS 调用
- r - R:按行索引重新排序数据框行
- javascript - react-google-maps/api 在某些状态更改后避免重新渲染地图
- python - 根据逻辑更改 DataFrame 列和数据
- django-rest-framework - 使用 Vue3 从 API 中成功删除项目后,异步函数不会更新
- java - 检查外部文件是否有某个单词,如果没有,则添加它 Java
- c++ - 将四个以上的参数传递给通过使用 ARM clang 6.6 中的内联汇编编写的包装函数调用的函数
- kotlin - 在 Exposed DAO 中返回空表达式?
- javascript - 优化 webpack 构建时间