invalid_request丢失:使用谷歌Passportjs谷歌Oauth2作用域

invalid_request丢失:使用谷歌Passportjs谷歌Oauth2作用域

问题描述:

认证代码中发展的问题,直到今年年初完美的工作,然后看起来打破了我的一点点改变,我试图倒退到以前的版本,并找到没有运气的原因。所以我正在寻求帮助修复今天存在的代码。invalid_request丢失:使用谷歌Passportjs谷歌Oauth2作用域

我使用nodejs v0.10.25 Passportjs通过Google和Facebook提供身份验证。我的包:

"config-multipaas": "^0.1.0", 
"restify": "^2.8.3", 
"googleapis": "~2.1.5", 
"mocha": "~2.3.3", 
"restify-redirect": "~1.0.0", 
"sequelize": "~3.12.2", 
"mysql": "~2.9.0", 
"passport": "~0.3.2", 
"passport-facebook": "~2.0.0", 
"passport-local": "~1.0.0", 
"passport-google-oauth": "~0.2.0", 
"sendgrid-webhook": "0.0.4", 
"sendgrid": "~2.0.0", 
"restify-cookies": "~0.2.0" 

两个星期前,在应用程序的另一部分工作时,我注意到,用户注册功能不再工作了两种服务。具体来说,Google Oauth2代码在初始许可页面后返回以下错误。

  1. That’s an error.

Error: invalid_request

Missing required parameter: scope

这里是我的策略定义的相关部分:

passport.use(new FacebookStrategy({ 
    clientID:  siteConfigs.facebook.clientId, 
     clientSecret: siteConfigs.facebook.clientSecret, 
     callbackURL: authRoot + 'facebook/callback', 
    profileFields: ['id','name','emails', 'picture', 'location', 'birthday', 'gender'] 
    }, 
    function(accessToken, refreshToken, profile, done){...} 

passport.use(new GooglePlusStrategy({ 
    clientID:  siteConfigs.google.clientId, 
     clientSecret: siteConfigs.google.clientSecret, 
     callbackURL: authRoot + 'google/callback', 
    profileFields: ['id','name','emails', 'gender', 'placesLived'] 
    }, 
    function(accessToken, refreshToken, profile, done){...} 

的令牌回调函数的机制是不相关的进程从来没有得到那么远(由节点调试器和控制台日志报表验证)。

这里是我的休息端点:

app.get('/auth/facebook', passport.authenticate('facebook', { session: false, scope: ['email']})); 

app.get('/auth/google', passport.authenticate('google', 
     { 
     scope: ['profile', 'email'], 
     accessType: 'online', 
     session: false 
     }) 
); 

app.get('/auth/:service/callback', function(req, res, next){ 
    console.log('Request:', req.path(), req.getQuery()); 

    passport.authenticate(req.params.service, 
    function(err, user, info){ 
     var returnPath = '/html/authcallback.html'; 

     if(err) 
      return res.redirect({ 
       pathname: returnPath, 
       query: { 
        error: err 
       } 
      }, next); 
     else 
      return res.redirect({ 
       pathname: returnPath, 
       query: { 
        id: user.id, 
        created: info 
       } 
      }, next); 
    })(req, res, next); 
}); 

一些初步的故障排除之后,我花了使用谷歌的OAuth 2.0游乐场定制的身份验证和令牌端点(在我的passportjs版本所使用的那些)的方法和我的拥有自己的客户端ID和密码,以便将每个交互与我的代码进行比较。最初的同意提示请求正常工作,并且与Playground匹配,并且回调将返回适当的代码,例如code=4/EUnaIvWpLIiHnKUR9WctOJKQ-_iWZ3_H9YeUYx7bJSo。但交换令牌代码的请求失败。使用节点调试器,评估重定向请求护照谷歌-的OAuth发回的令牌,它建立的网址是:

https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http://localhost:8080/auth/google/callback&client_id=<ID>

与此相比,从谷歌的Oauth 2.0游乐场类似的请求,这将看起来像:

http://www.googleapis.com?code=4/9uaUYjeExmPftgRLsRZ8MCc2e_7YGHow7kvew6Fkypo&redirect_uri=https://developers.google.com/oauthplayground&client_id=<ID>&client_secret=<SECRET>&scope=&grant_type=authorization_code

有几个参数,从我的查询字符串缺少,两个最重要的是我的代码和秘密。我原以为Google的服务会为这些人返回一个错误。相反,它会为流程中的这一步实际不需要的缺失范围参数返回一个错误(我不知道操场应用程序为什么包含它)。

最后,我相当肯定它在Facebook战略开始失败的时候也在我的身边。经过同意后,它回到我的回调多个代码的奇怪,然后最终返回一个TOO_MANY_REDIRECTS错误。

那么,任何人有任何想法?再一次,这个相同的代码一直工作到年初,然后在一段时间后开始失败。

+0

这已经上涨了一个半星期了。只是想知道有没有人有任何想法。 –

+0

我自己解决了这个问题。社区绝对没有答案。当我试图与passportjs开发人员/维护人员分享问题链接时,他的回应是尝试销售合同服务来解决问题。 考虑关闭该问题。 –

+0

感谢分享(不)。 –

几周前我问了this same question,偶然发现了一个答案。我很高兴分享它:

Seems I was missing the following code after initializing the server:

api.use(restify.plugins.queryParser({ mapParams: false })); 

Once I added that line, I no longer saw the Google error, and the process passed back to my code.