11

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

  1. That’s an error.

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.

1

5 Answers 5

24

When defining the GoogleStrategy, the JSON key should be callbackURL instead of callbackUrl (i.e., capital URL). Had this 'issue' as well ;-)

2
  • Thank you! That worked. I knew I was missing something. I never thought it was something so simple.
    – Trewaters
    Oct 8, 2015 at 11:20
  • 1
    for me i had callBackURL, had to make as you said 'callbackURL'
    – Fernando B
    Oct 5, 2017 at 2:21
1

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:

    1. Under APIs and auth | Credentials | OAuth consent screen - all the required url.
    2. Under APIs and auth | Credentials - look for your web api client and see you authorized all the relevant URIs. The auth will not work if the call is from or the redirection is to a page that was not listed in this section.
2
  • That didn't work. Thanks for the suggestions but I still get an empty redirect_uri field. I assume there is somewhere in my server code that is missing the redirect_uri. The rest of the code in the error is coming from my code. I can manually insert the ?missing? redirect_uri and the request continues to process like normal.
    – Trewaters
    Oct 5, 2015 at 11:36
  • You can dig into the module. search for the specific string and see where it happens. All the modules are nested in your node_modules directory
    – Meir
    Oct 5, 2015 at 13:11
1

I use something like that- 1. Make sure that's URL and not uri. 2. Make sure the callback URL you registered is same as the one you are requesting for.


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

// Use the GoogleStrategy within Passport.
//   Strategies in Passport require a `verify` function, which accept
//   credentials (in this case, an accessToken, refreshToken, and Google
//   profile), and invoke a callback with a user object.
passport.use(new GoogleStrategy({
    clientID: GOOGLE_CLIENT_ID,
    clientSecret: GOOGLE_CLIENT_SECRET,
    callbackURL: "http://www.example.com/auth/google/callback"
    //should be same as the one you registered in credentials.
  },
  function(accessToken, refreshToken, profile, done) {
       User.findOrCreate({ googleId: profile.id }, function (err, user) {
         return done(err, user);
       });
  }
));


P.S:my first one on stackoverflow. please ignore mistakes and help me in improving.

0

My issue occuors in authenticate with WSL. This error bellow is presented:

error issue

To solved , utilize the command gcloud init --console-only in your terminal.

0

I had this issue to. in my nestJs Application. I solved it by changing the CallbackURL from "callbackUrl" to "callbackURL" URL all caps

Not the answer you're looking for? Browse other questions tagged or ask your own question.