缺少必需参数:redirect_uri with passport-google-oauth

Tre*_*ers 2 node.js express google-oauth2 passport-google-oauth

使用passport-google-oauth: "0.2.0"在我MEAN堆栈的应用程序(这里找到:https://github.com/jaredhanson/passport-google-oauth).当我运行该应用程序并尝试使用Google API登录时,会返回此错误

  1. 那是一个错误.

错误:invalid_request

缺少必需参数:redirect_uri

请求详细信息scope = https://www.googleapis.com/auth/plus.login response_type = code redirect_uri = client_id = xxxx-xxxx.apps.googleusercontent.com

重定向参数在这里 passport-init.js

var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;

var GOOGLE_CLIENT_ID ="xxx-xxx.apps.googleusercontent.com"; var GOOGLE_CLIENT_SECRET ="xxxx";

passport.use(新的GoogleStrategy({
clientID:GOOGLE_CLIENT_ID,
clientSecret:GOOGLE_CLIENT_SECRET,
callbackUrl:" http://127.0.0.1:3000/auth/google/oauth2callback "},function(accessToken,refreshToken,profile,done){done( null,profile);}));

路线在这里 authenticate.js

router.get('/ google',passport.authenticate('google',{scope:[' https://www.googleapis.com/auth/plus.login ']}),function(req,res){} );

router.get('/ google/oauth2callback',passport.authenticate('google',{successRedirect:'/ auth/success',failureRedirect:'/ auth/failure'}),function(req,res){res.redirect ('/');});

我确信我遗漏了一些简单的东西,但我不知道在这个问题中添加什么会给你最好的信息.请问,我会尽力回答你.这就像是相关数据.

有趣的是,如果我手动添加callbackUrl,那么一切都很好.我可以很好地使用Google API.然后我可以选择"允许"或"拒绝"请求.

小智 17

在定义GoogleStrategy时,JSON键应该是callbackURL而不是callbackUrl(即大写URL).还有这个'问题';-)