Skip to content

Instantly share code, notes, and snippets.

@billsaysthis
Created September 2, 2011 21:23
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 billsaysthis/1189967 to your computer and use it in GitHub Desktop.
Save billsaysthis/1189967 to your computer and use it in GitHub Desktop.
var auth_middleware = function() {
return function(req, res, next) {
var urlp= url.parse(req.url, true)
if( urlp.query.login_with ) {
req.authenticate([urlp.query.login_with], function(error, authenticated) {
if( error ) {
// Something has gone awry, behave as you wish.
console.log( error );
res.end();
} else {
if( authenticated === undefined ) {
// The authentication strategy requires some more browser interaction, suggest you do nothing here!
} else {
// We've either failed to authenticate, or succeeded (req.isAuthenticated() will confirm, as will the value of the received argument)
next();
}
}
});
} else {
next();
}
}
};
var app = express.createServer(
express.bodyParser(),
express.static(__dirname + "/public"),
express.cookieParser(),
auth_middleware(),
express.session({ secret: 'htuayreve', isAuth: false, store: new express.session.MemoryStore({ reapInterval: -1 }) })
);
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(
auth({strategies: [
auth.Twitter({consumerKey: conf.twit.consumerKey, consumerSecret: conf.twit.consumerSecret}) ],
logoutHandler: require('./lib/ca-events').redirectOnLogout("/")
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment