使用Node.js/Passport在Google身份验证回调中缺少范围错误

Gar*_*ary 16 javascript heroku node.js passport.js

此错误仅在Heroku(生产)上发生,而不是在本地发生.我试过了两个:

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

和,

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

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

当我转到Google身份验证链接时,范围IS在URL中.在我的实时制作应用中生成的没有区别.

但我仍然得到:

Error 400

Error: invalid_request

Missing required parameter: scope
Run Code Online (Sandbox Code Playgroud)

Sha*_*rry 6

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

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

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

openid profile email https://www.googleapis.com/auth/drive.file
Run Code Online (Sandbox Code Playgroud)

来源(S):

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