Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passport w/node.js Google error

I'm attempting to use passport with an express/node.js app. For some reason I can't authenticate using google. Google gives the following error:

Error: invalid_request
Error in parsing the OpenID auth request.

Code:

    passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(user, done) {
  done(null, user);
});

var GoogleStrategy = require('passport-google').Strategy;
var UserModel = require('./models/usermodel');

passport.use(new GoogleStrategy({
    returnURL: 'http://localhost:3000/auth/google/return',
    realm: 'http:/localhost:3000'
  },
  function(identifier, profile, done) {
    profile.email = profile.emails[0].value;
    UserModel.findOneAndUpdate({email:profile.email}, {$set:profile, $inc:{logins:1}}, {upsert:true}, done);
  }
));
like image 531
chris_mac Avatar asked Dec 11 '25 07:12

chris_mac


1 Answers

If you don't otherwise have reason to use OpenID, I highly recommend switching to OAuth 2.0, which is implemented in passport-google-oauth.

Google seems to be recommending that as their preferred authentication solution, and their OpenID implementation seems to receive less attention and spurious errors occur.

like image 59
Jared Hanson Avatar answered Dec 14 '25 00:12

Jared Hanson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!