Created
February 7, 2016 18:31
-
-
Save zkochan/ecccaaa2a85a4050d6bc to your computer and use it in GitHub Desktop.
hexi-passport API
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
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