oauth-2.0 - Passport.js 对 Gmail API 进行身份验证导致 GooglePlusAPIError
问题描述
我使用 Passport.js 向 Google 进行身份验证。我定义了以下范围:
passport.authenticate('google', {
scope: [
'https://www.googleapis.com/auth/gmail.modify',
],
})
所以,我只想访问 Gmail API。
现在,谷歌回应:
GooglePlusAPIError: Insufficient Permission
当我通过 Google API 仪表板将 Google+ API 添加到我的项目中并将以下范围添加到我的 passport.authenticate 调用时,我得到了它:
'https://www.googleapis.com/auth/userinfo.email'
但是,当我只想访问 Gmail 时,为什么还需要 Google+ API?
我还找到了这个网站:https ://developers.google.com/gmail/api/auth/web-server他们在其中设置了这些范围:
SCOPES = [
'https://www.googleapis.com/auth/gmail.readonly',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
# Add other requested scopes.
]
我错过了什么?
提前致谢!
干杯,尼尔斯
编辑:
我刚刚研究了我的 Google API 仪表板并找到了下面的屏幕。那么,这些范围是强制性的吗?
编辑 2
上下文是一个 Express.js 应用程序。整个调用看起来像:
router.get('/google', passport.authenticate('google', {
scope: [
'https://www.googleapis.com/auth/gmail.modify',
],
}));
router.get('/google/callback', passport.authenticate('google', {
failureRedirect: '/',
}), (req, res) => {
req.session.token = req.user.token;
res.redirect('/');
});
解决方案
推荐阅读
- javascript - dc.js - 热图的矩形画笔?
- python - Python Pandas - 向每一行添加新的总和
- android - Libgdx 和 Google Play 计费
- css - 如何降低顶部菜单栏的高度
- java - Maven 程序集插件目标“jar-with-dependencies”不包含来自子 pom 的 jar 文件
- sqlite - 删除 SQLite 中的重复组
- javascript - 为远程文件(视频、照片等)创建 blob url 下载链接
- rust - 为什么“rev”在 Cargo 中不起作用?
- django - Django 如何仅将 example.com 重定向到 https 并将 *.example.com 重定向到 http?
- java - 使用同步或不低于为所有线程生成相同哈希码的代码。如何?