Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Integrate NowJS with Express and Passport

View gist:2266544
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
var express = require('express')
, passport = require('passport')
, sessionStore = new express.session.MemoryStore()
 
, app = module.exports = express.createServer()
 
, nowjs = require('now');
 
app.configure( function () {
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('connect'));
app.use(express.session({ secret : "connect", store : sessionStore }));
app.use(passport.initialize());
app.use(passport.session());
 
app.use(express.errorHandler({dumpExeptions: true, showStack : true}));
 
app.use(app.router);
});
 
nowjs.on('connect', function() {
var self = this;
 
if ( this.user.cookie && this.user.cookie['connect.sid'] ) {
var sid = decodeURIComponent( this.user.cookie['connect.sid'] );
sessionStore.get( sid, function( err, session ) {
if ( session ) {
passport.deserializeUser(session.passport.user, function(err, user) {
self.user.session.passport = user;
});
}
});
};
});
 
var everyone = nowjs.initialize(app);
app.listen(3000);
console.log('app is listening');
 
everyone.now.getUsername( function (cb) {
if ( this.user.session && this.user.session.passport && this.user.session.username ) cb(this.user.session.username);
});
Owner

Of course you should have written your passport Strategy file and authentication mechanism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.