Google Single Sign On (SSO) module
Simple authentication with Google SSO.
Usage
In your main module:
require('google-sso-auth')({
clientID: 'your google client id',
clientSecret: 'your google secret key',
callbackURL: 'authentication callback url',
sessionSecretId: 'your session secret id'
}, app, passport);
In your routes module:
app.get('/auth/google', passport.authenticate('google', { scope : ['profile', 'email'] }));
app.get('/auth/google/callback', passport.authenticate('google', {
successRedirect : '/profile',
failureRedirect : '/'
}));
You can use a helper method:
function isLoggedIn(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
res.redirect('/');
}
...
app.get('/profile', isLoggedIn, function(req, res) {
...
});
Accessing user information
You can anytime access Google profile information from req.user
.
User information format:
{
googleProfile: {
provider: 'google',
id: 'user google id',
displayName: 'user display name',
name: {
familyName: 'user family name',
givenName: 'user given name'
},
emails: [ { value: 'user e-mail' } ],
_json: {
id: 'user google id',
email: 'user e-mail',
verified_email: true,
name: 'user display name',
given_name: 'user given name',
family_name: 'user family name',
picture: 'user profile picture url',
locale: 'user locale',
hd: 'user domain'
},
token: 'user access token'
}
}
Access user e-mail: req.user.googleProfile.emails[0].value