【问题标题】:Missing scope error on Google authentication callback using Node.js/Passport使用 Node.js/Passport 的 Google 身份验证回调缺少范围错误
【发布时间】:2015-04-22 05:13:31
【问题描述】:

此错误仅发生在 Heroku(生产)上,而不发生在本地。 我都试过了:

passport.authenticate('google', { scope: 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/analytics.readonly' })

还有,

passport.authenticate('google', { scope: ['profile', 'email'] })

范围是数组,还是空格分隔的字符串。

当我转到 Google 身份验证链接时,URL 中的范围是 IS。在我的现场制作应用程序中生成的没有区别。

但我仍然得到:

Error 400

Error: invalid_request

Missing required parameter: scope

【问题讨论】:

  • 您是否尝试过在 Google Developer Console 中查看您的 Google 应用?我猜您可能没有在其中为您的生产应用程序提供授权的重定向 URI(假设它在本地工作,这是最有可能的情况)。有时谷歌给出的错误是不正确/模棱两可的(我已经学会了这一点)。

标签: javascript node.js heroku passport.js


【解决方案1】:

我认为您使用的是 Passport Google OAuth,而不仅仅是 Passport Google (OpenId) 模块?

如果您使用的是 OAuth 护照,则使用 Google 进行身份验证需要额外的范围参数。

作为字符串传递,您必须将 'openid' 作为第一个单词传递,例如: 例如,如果您希望按文件访问用户的 Google Drive,

openid profile email https://www.googleapis.com/auth/drive.file

来源:

https://developers.google.com/identity/protocols/OpenIDConnect#scope-param https://developers.google.com/+/api/oauth#login-scopes

【解决方案2】:

对于错误信息

Error 400
Error: invalid_request
Missing required parameter: scope

您需要在表单中添加范围

<input type="hidden" name="scope" value="https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/tasks https://www-opensocial.googleusercontent.com/api/people https://www.googleapis.com/auth/plus.login" />

请参考spring social login 与linkedin、facebook、twitter 和google 供应商示例应用程序。

【讨论】:

  • 请不要对多个问题发布相同的答案。发布一个好的答案,然后投票/标记以关闭其他问题作为重复问题。如果问题不是重复的,调整你对问题的回答。重复链接到你自己的外部工作时更是如此,而不注意这个事实。
  • 实际上这两个帖子都与相同的错误消息和问题有关。因为我用上面的语句解决了这个问题,所以与其他人分享我的解决方案。当然我以后不会在这里复制我的帖子了。
猜你喜欢
  • 2020-09-24
  • 2017-03-10
  • 2015-03-16
  • 2015-06-01
  • 1970-01-01
  • 2014-09-01
  • 1970-01-01
  • 2020-11-23
  • 2021-12-12
相关资源
最近更新 更多