Skip to content

Instantly share code, notes, and snippets.

@christianstrang
Created July 9, 2019 08:18
Show Gist options
  • Save christianstrang/598fcd119b36cce02c2010ac628a54bc to your computer and use it in GitHub Desktop.
Save christianstrang/598fcd119b36cce02c2010ac628a54bc to your computer and use it in GitHub Desktop.
SailsJS PassportController for Google OAuth2 Authentication
/**
* PassportController
*
* @description :: Server-side actions for handling incoming requests.
* @help :: See https://sailsjs.com/docs/concepts/actions
*/
var passport = require('passport');
module.exports = {
googleAuth: function(req, res) {
passport.authenticate('google', { scope: ['email', 'profile'] })(req, res);
},
googleCallback: function(req, res, next) {
passport.authenticate('google', function(err, user) {
if(err) {
// redirect to login page
console.log('google callback error: '+err);
} else {
console.log('google credentials');
console.log(user);
res.json(user);
}
})(req, res, next);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment