Created
July 9, 2019 08:18
-
-
Save christianstrang/598fcd119b36cce02c2010ac628a54bc to your computer and use it in GitHub Desktop.
SailsJS PassportController for Google OAuth2 Authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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