Skip to content

Instantly share code, notes, and snippets.

@zkochan
Created February 7, 2016 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkochan/ecccaaa2a85a4050d6bc to your computer and use it in GitHub Desktop.
Save zkochan/ecccaaa2a85a4050d6bc to your computer and use it in GitHub Desktop.
hexi-passport API
server.route.pre(function(next, opts) {
if (!opts.config.passport) return next(opts);
if (opts.config.passport.authenticate) {
opts.handler = [
function(req, res, next) {
var passportOpts = opts.config.passport.authenticate[req.params.provider] ||
opts.config.passport.authenticate.default;
passport.authenticate(req.params.provider, passportOpts)(req, res, next);
},
].concat(opts.handler);
}
if (opts.config.passport.authorize) {
opts.handler = [
function(req, res, next) {
passport.authorize(req.params.provider, opts.config.passport.authorize)(req, res, next);
},
].concat(opts.handler);
}
return next(opts);
});
server.route({
method: 'GET',
path: '/auth/:provider',
config: {
passport: {
authenticate: {
facebook: { scope: ['email', 'user_location'] },
google: { scope: 'profile email' },
linkedin: { state: 'SOME STATE' },
},
},
},
});
server.route({
method: 'GET',
path: '/auth/:provider/callback',
config: {
passport: {
authenticate: {
default: { failureRedirect: '/login' },
},
},
},
handler: function(req, res) {
res.redirect(req.session.returnTo || '/');
},
});
server.route({
method: 'GET',
path: '/auth/(foursquare|tumblr|venmo|steam)',
config: {
passport: {
authorize: {
venmo: { scope: 'make_payments access_profile access_balance access_email access_phone' },
google: { scope: 'profile email' },
linkedin: { state: 'SOME STATE' },
},
},
},
});
server.route({
method: 'GET',
path: '/auth/(foursquare|tumblr|venmo|steam)/callback',
config: {
passport: {
authorize: {
default: { failureRedirect: '/login' },
},
},
},
handler: function(req, res) {
res.redirect(req.session.returnTo || '/');
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment