Skip to content

Commit

Permalink
Improve compatibility with old strategies and new lazy sessions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Nov 9, 2015
1 parent aa74207 commit e62afe0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
16 changes: 14 additions & 2 deletions lib/framework/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@ var initialize = require('../middleware/initialize')
* @return {Object}
* @api protected
*/
module.exports = function() {
exports = module.exports = function() {

// HTTP extensions.
require('../http/request');
exports.__monkeypatchNode();

return {
initialize: initialize,
authenticate: authenticate
};
};

exports.__monkeypatchNode = function() {
var http = require('http');
var IncomingMessageExt = require('../http/request');

http.IncomingMessage.prototype.login
http.IncomingMessage.prototype.logIn = IncomingMessageExt.logIn;
http.IncomingMessage.prototype.logout
http.IncomingMessage.prototype.logOut = IncomingMessageExt.logOut;
http.IncomingMessage.prototype.isAuthenticated = IncomingMessageExt.isAuthenticated;
http.IncomingMessage.prototype.isUnauthenticated = IncomingMessageExt.isUnauthenticated;
};
6 changes: 4 additions & 2 deletions lib/http/request.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/**
* Module dependencies.
*/
var http = require('http')
, req = http.IncomingMessage.prototype;
//var http = require('http')
// , req = http.IncomingMessage.prototype;


var req = exports = module.exports = {};

/**
* Intiate a login session for `user`.
*
Expand Down
7 changes: 7 additions & 0 deletions lib/middleware/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Module dependencies.
*/
var http = require('http')
, IncomingMessageExt = require('../http/request')
, AuthenticationError = require('../errors/authenticationerror');


Expand Down Expand Up @@ -78,6 +79,12 @@ module.exports = function authenticate(passport, name, options, callback) {
}

return function authenticate(req, res, next) {
if (http.IncomingMessage.prototype.logIn
&& http.IncomingMessage.prototype.logIn !== IncomingMessageExt.logIn) {
require('../framework/connect').__monkeypatchNode();
}


// accumulator for failures from each strategy in the chain
var failures = [];

Expand Down

0 comments on commit e62afe0

Please sign in to comment.