diff --git a/lib/http/request.js b/lib/http/request.js index 3e6cc4e5..db74ef01 100644 --- a/lib/http/request.js +++ b/lib/http/request.js @@ -37,7 +37,7 @@ req.logIn = function(user, options, done) { if (typeof done != 'function') { throw new Error('req#login requires a callback function'); } var self = this; - this._passport.instance._sm.logIn(this, user, function(err) { + this.sessionManager.logIn(this, user, function(err) { if (err) { self[property] = null; return done(err); } done(); }); @@ -57,7 +57,7 @@ req.logOut = function() { this[property] = null; if (this._passport) { - this._passport.instance._sm.logOut(this); + this.sessionManager.logOut(this); } }; diff --git a/lib/middleware/initialize.js b/lib/middleware/initialize.js index 724982b6..eee25ad7 100644 --- a/lib/middleware/initialize.js +++ b/lib/middleware/initialize.js @@ -56,6 +56,9 @@ module.exports = function initialize(passport, options) { req.isAuthenticated = IncomingMessageExt.isAuthenticated; req.isUnauthenticated = IncomingMessageExt.isUnauthenticated; + // expose session manager + req.sessionManager = passport._sm; + if (options.userProperty) { req._userProperty = options.userProperty; } diff --git a/test/http/request.test.js b/test/http/request.test.js index 61f8f20e..62b230f8 100644 --- a/test/http/request.test.js +++ b/test/http/request.test.js @@ -201,6 +201,7 @@ describe('http.ServerRequest', function() { req.isUnauthenticated = request.isUnauthenticated; req._passport = {}; req._passport.instance = passport; + req.sessionManager = passport._sm; req.session = {}; var error; @@ -246,6 +247,7 @@ describe('http.ServerRequest', function() { req.isUnauthenticated = request.isUnauthenticated; req._passport = {}; req._passport.instance = passport; + req.sessionManager = passport._sm; req.session = {}; req._userProperty = 'currentUser'; @@ -296,6 +298,7 @@ describe('http.ServerRequest', function() { req.isUnauthenticated = request.isUnauthenticated; req._passport = {}; req._passport.instance = passport; + req.sessionManager = passport._sm; req.session = {}; req.session['passport'] = {}; @@ -378,6 +381,7 @@ describe('http.ServerRequest', function() { req.user = { id: '1', username: 'root' }; req._passport = {}; req._passport.instance = passport; + req.sessionManager = passport._sm; req.session = {}; req.session['passport'] = {}; req.session['passport'].user = '1'; @@ -409,6 +413,7 @@ describe('http.ServerRequest', function() { req._passport = {}; req._passport.instance = passport; req._userProperty = 'currentUser'; + req.sessionManager = passport._sm; req.session = {}; req.session['passport'] = {}; req.session['passport'].user = '1';