Skip to content

Instantly share code, notes, and snippets.

@peny
Last active August 29, 2015 14:01
Show Gist options
  • Save peny/eb171bac688c5ac2c208 to your computer and use it in GitHub Desktop.
Save peny/eb171bac688c5ac2c208 to your computer and use it in GitHub Desktop.
OpenID auth request contains an unregistered domain

So, you're using hapi and travelogue with passport-google and nothing is working? It probably works fine with passport.js and express.js but that's not what we want.

It worked fine with localhost as your hostname but now we're doing it for real and everything breaks.

Google is helpful enough to give you: OpenID auth request contains an unregistered domain

Unregistered where? In the dev console? It's not even linked to so it can't be that. (It's here by the way.)

Just use passport-google-oauth!

Register your app

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

var Passport = server.plugins.travelogue.passport;

Passport.use(new GoogleStrategy({
      clientID: CONFIG.Google.clientId,
      clientSecret: CONFIG.Google.clientSecret,
      callbackURL: CONFIG.Google.returnURL
  },
  function(accessToken, refreshToken, profile, done) {
    var user = {
      identifier: profile.id,
      email: profile.emails[0].value,
      name: profile.displayName
    };

    User.getOrCreateUser(user, function(err,res){
      done(null, res);
    });
  }
));

Passport.serializeUser(function(user,cb){
  cb(null, user._id);
});

Passport.deserializeUser(function(userId,cb){
  User.getUserById({_id: userId},function(err,user){
    cb(err, user.toObject());
  });
});

And over in /routes/auth.js:

module.exports = [
{
  path: '/auth/google',
  method: 'GET',
  handler: authGoogle
},
{
  path: '/auth/google/return',
  method: 'GET',
  handler: authGoogleReturn
}
];

function authGoogle(request, reply){
  var passport = request.server.plugins.travelogue.passport;

  passport.authenticate('google',
    {
      scope:
      [
        'https://www.googleapis.com/auth/userinfo.profile',
        'https://www.googleapis.com/auth/userinfo.email'
      ]
    })(request,reply);
}


function authGoogleReturn(request,reply){
  var passport = request.server.plugins.travelogue.passport;
  
  passport.authenticate('google')(request, reply);
}

It should work better (at all) now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment