From 1ab23aa5249f59903822a07cc30eb1512aae319d Mon Sep 17 00:00:00 2001 From: Deryk Sinotte Date: Sun, 23 Feb 2014 12:37:35 -0800 Subject: [PATCH] Pass request to callback in DigestStrategy Like other strategies, it would be nice to have access to there request in the DigestStrategy. --- lib/passport-http/strategies/digest.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/passport-http/strategies/digest.js b/lib/passport-http/strategies/digest.js index 1984d89..14f21ed 100644 --- a/lib/passport-http/strategies/digest.js +++ b/lib/passport-http/strategies/digest.js @@ -77,6 +77,7 @@ function DigestStrategy(options, secret, validate) { } this._opaque = options.opaque; this._algorithm = options.algorithm; + this._passReqToCallback = options.passReqToCallback; if (options.qop) { this._qop = (Array.isArray(options.qop)) ? options.qop : [ options.qop ]; } @@ -128,10 +129,11 @@ DigestStrategy.prototype.authenticate = function(req) { // However, the user will only be successfully authenticated if the password // is correct, as indicated by the challenge response matching the computed // value. - this._secret(creds.username, function(err, user, password) { + + var secretHandler = function(err, user, password) { if (err) { return self.error(err); } if (!user) { return self.fail(self._challenge()); } - + var ha1; if (!creds.algorithm || creds.algorithm === 'MD5') { if (typeof password === 'object' && password.ha1) { @@ -151,7 +153,7 @@ DigestStrategy.prototype.authenticate = function(req) { } else { return self.fail(400); } - + var ha2; if (!creds.qop || creds.qop === 'auth') { ha2 = md5(req.method + ":" + creds.uri); @@ -166,7 +168,7 @@ DigestStrategy.prototype.authenticate = function(req) { } else { return self.fail(400); } - + var digest; if (!creds.qop) { digest = md5(ha1 + ":" + creds.nonce + ":" + ha2); @@ -175,7 +177,7 @@ DigestStrategy.prototype.authenticate = function(req) { } else { return self.fail(400); } - + if (creds.response != digest) { return self.fail(self._challenge()); } else { @@ -195,7 +197,14 @@ DigestStrategy.prototype.authenticate = function(req) { self.success(user); } } - }); + }; + + if (self._passReqToCallback) { + this._secret(req, creds.username, secretHandler); + } else { + this._secret(creds.username, secretHandler); + } + } /**