Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/passport-http/strategies/digest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -175,7 +177,7 @@ DigestStrategy.prototype.authenticate = function(req) {
} else {
return self.fail(400);
}

if (creds.response != digest) {
return self.fail(self._challenge());
} else {
Expand All @@ -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);
}

}

/**
Expand Down