Javascript 使用Node.js/Passport的Google身份验证回调上缺少作用域错误

Javascript 使用Node.js/Passport的Google身份验证回调上缺少作用域错误,javascript,node.js,heroku,passport.js,Javascript,Node.js,Heroku,Passport.js,此错误仅发生在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']}) 作用域是数组还是空

此错误仅发生在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中。在我的实时制作应用程序中生成的一个没有区别

但我仍然得到:

Error 400

Error: invalid_request

Missing required parameter: scope

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

如果您使用的是OAuth passport,那么使用Google进行身份验证需要一个额外的作用域参数

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

openid profile email https://www.googleapis.com/auth/drive.file
资料来源:

查看错误消息

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" />


请参考linkedin、facebook、twitter和google providers示例应用程序。

您是否尝试过在google开发者控制台中查看您的google应用程序?我猜您可能没有为您的生产应用程序提供授权重定向URI(假设它在本地工作,这是最有可能的情况)。有时谷歌给出的错误是不正确的/模棱两可的(我通过艰苦的学习了解到这一点)。vs这里的答案也不错:请不要在多个问题上发布相同的答案。发布一个好的答案,然后投票/标记以重复结束其他问题。如果问题不是重复的,请根据问题定制您的答案。当你反复链接到自己的外部工作时,更是如此,没有注意到这一事实。实际上,这两篇文章都有相同的错误消息和问题。由于我用上述声明解决了这个问题,所以将我的解决方案与其他人分享。当然,我以后不会在这里重复我的文章。