Created
September 2, 2011 21:23
-
-
Save billsaysthis/1189967 to your computer and use it in GitHub Desktop.
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
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