Missing required parameter: redirect
Using passport-google-oauth: "0.2.0"
in my MEAN Stack application (found here: https://github.com/jaredhanson/passport-google-oauth). When I run the application and attempt to sign in with a Google API this error is returned
Error: invalid_request
Missing required parameter: redirect_uri
Request Details scope=https://www.googleapis.com/auth/plus.login response_type=code redirect_uri= client_id=xxxx-xxxx.apps.googleusercontent.com
The redirect param is here 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(new 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); } ));
The routes are here 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('/');} );
I am sure I am missing something simple, but I don't know what to add in this question that will give you the best information. Please ask and I will do my best to answer you. This is what feels like the pertinent data.
Funny thing is if I add the callbackUrl manually then everything works great. I can reach the Google API fine. Then I am given the choice to "allow" or "deny" the request.
When defining the GoogleStrategy, the JSON key should be callbackURL instead of callbackUrl (ie, capital URL). Had this 'issue' as well ;-)
I have a working example using the same strategy. Since I don't get this error, can't pinpoint what the problem is, but I wanted to suggest you check the following:
add to your google strategy creation (new GoogleStrategy({...})) the scope:
scope: 'https://www.googleapis.com/auth/userinfo.email',
Make sure your google api is configured properly in the dev api console. Specifically:
上一篇: 在nodejs中使用护照进行身份验证时未获得预期的结果
下一篇: 缺少必需的参数:重定向