Skip to content

Instantly share code, notes, and snippets.

@nkbt
Created February 28, 2014 13:39
Show Gist options
  • Save nkbt/9271275 to your computer and use it in GitHub Desktop.
Save nkbt/9271275 to your computer and use it in GitHub Desktop.
Passport.js Routes
"use strict";
var passport = require('./passport');
var config = {
redirectBack: redirectBack
}
function redirectBack(req, res) {
res.redirect(req.param('__back') && decodeURIComponent(req.param('__back')) || '/');
}
function logout(req, res) {
req.logout();
res.redirect('/auth/guest');
}
function passportRoutes(app) {
app.get('/auth/guest', passport().authenticate('guest'), redirectBack);
app.get('/auth/twitter', passport().authenticate('twitter'));
app.get('/auth/twitter/callback', passport().authenticate('twitter'), config.redirectBack);
app.get('/auth/facebook', passport().authenticate('facebook'));
app.get('/auth/facebook/callback', passport().authenticate('facebook'), config.redirectBack);
app.get('/auth/linkedin', passport().authenticate('linkedin'));
app.get('/auth/linkedin/callback', passport().authenticate('linkedin'), config.redirectBack);
app.get('/auth/logout', logout);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment