Skip to content

Commit 951f588

Browse files
committed
Switching to http-auth module for digest auth option
1 parent c62a918 commit 951f588

File tree

3 files changed

+21
-196
lines changed

3 files changed

+21
-196
lines changed

http-digest.js

Lines changed: 0 additions & 191 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
"author" : "Mike Mattozzi <[email protected]>",
77
"main" : "./webrepl.js",
88
"engines": {
9-
"node": ">=0.8.0"
9+
"node": ">=4.2.3"
1010
},
1111
"repository": {
1212
"type": "git",
1313
"url": "git://github.com/mmattozzi/webrepl.git"
1414
},
1515
"dependencies": {
16-
"http-digest": ">=0.1.0"
16+
"http-auth": ">=2.2.8"
1717
},
1818
"keywords": [ "repl", "console", "management" ]
1919
}

webrepl.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,25 @@ ReplHttpServer.prototype.start = function(port) {
4747
var self = this;
4848
if (this.username !== undefined && this.password !== undefined) {
4949
// Set up server that requires http digest authentication
50-
var httpdigest = require('./http-digest');
51-
self.server = httpdigest.createServer(this.username, this.password,
52-
function(req, res) { self.route(req, res); });
50+
var configuredUsername = this.username;
51+
var configuredPassword = this.password;
52+
var auth = require('http-auth');
53+
var crypto = require('crypto');
54+
55+
var digest = auth.digest({ realm: "webrepl" },
56+
function (username, callback) { // Expecting md5(username:realm:password) in callback.
57+
if (username === configuredUsername) {
58+
var md5hash = crypto.createHash('md5');
59+
callback(md5hash.update(configuredUsername + ":webrepl:" + configuredPassword).digest("hex"));
60+
} else {
61+
callback();
62+
}
63+
}
64+
);
65+
66+
self.server = http.createServer(digest, function(req, res) {
67+
self.route(req, res);
68+
});
5369
self.server.listen(port, this.hostname);
5470
} else {
5571
// No auth required

0 commit comments

Comments
 (0)