redirect_uri的参数值无效:Missing scheme:/ auth / google_auth_code / callback

编辑这是一个最小的可行的项目

我正尝试从服务器端stream的授权代码获取来自Google的访问和刷新令牌。 我遵循Google的指南: https : //developers.google.com/identity/sign-in/web/server-side-flow 。

我正在使用护照和护照-Google-authcode 。

以下是节点应用的路由:

router.get('/auth/google_auth_code', passport.authenticate('google_authcode', { scope: [ 'https://www.googleapis.com/auth/calendar', 'profile', 'https://www.googleapis.com/auth/userinfo.email' ] }), function () { res.end(); }) router.get('/auth/google_auth_code/callback', passport.authenticate('google_authcode', { failureRedirect: '/error' }), function (req, res) { // do something with req.user res.send('hello'); } ); 

这是该策略的护照configuration。

 passport.use('google_authcode', new GoogleAuthCodeStrategy({ clientID: 'my client id', clientSecret: 'my secret', callbackURL: '/auth/google_auth_code/callback', // passReqToCallback: true }, function (accessToken, refreshToken, rawResponse, profile, done) { // unable to get here } )); 

当发出authentication请求时,Google会回应以下错误:

 { "error" : "invalid_request", "error_description" : "Invalid parameter value for redirect_uri: Missing scheme: /auth/google_auth_code/callback" } 

以下是我在Google控制台中的凭证设置:

在这里输入图像描述

在这一点上,我不知道还有什么要做。 我也尝试将passport中的callbackURL改为绝对URL。 我肯定会得到一个有效的authentication代码(它看起来像: 4/Mb2pcOyhYhziROyFHKH5pnzvUldYbAmMop9SJKbBHXQ )。 让我知道是否还有更多我可以提供的相关信息。

谢谢,
山姆

编辑

我注意到,我有以上斜杠结束的URL。 我修正了这个问题,但是我没有更新屏幕截图。

如果我使用完整的URL(例如` http:// localhost:8080 // auth / google_auth_code / callback ),我得到以下错误:

 { "error" : "unauthorized_client" } 

如果我使用完整的URL(例如` http:// localhost:8080 / auth / google_auth_code / callback ),我得到以下错误:

 { "error" : "redirect_uri_mismatch" } 

似乎是护照 – 谷歌错误,你可能会在这里看到: https : //github.com/jaredhanson/passport-google-oauth/issues/21

他们build议在这个问题上使用: https : //github.com/sqrrrl/passport-google-plus

它的开源代码是如何工作的,你必须修复你的自我或find另一个包。