Skip to content

Commit

Permalink
Switching to http-auth module for digest auth option
Browse files Browse the repository at this point in the history
  • Loading branch information
mmattozzi committed Dec 5, 2015
1 parent c62a918 commit 951f588
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 196 deletions.
191 changes: 0 additions & 191 deletions http-digest.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"author" : "Mike Mattozzi <mike.mattozzi@gmail.com>",
"main" : "./webrepl.js",
"engines": {
"node": ">=0.8.0"
"node": ">=4.2.3"
},
"repository": {
"type": "git",
"url": "git://github.com/mmattozzi/webrepl.git"
},
"dependencies": {
"http-digest": ">=0.1.0"
"http-auth": ">=2.2.8"
},
"keywords": [ "repl", "console", "management" ]
}
22 changes: 19 additions & 3 deletions webrepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,25 @@ ReplHttpServer.prototype.start = function(port) {
var self = this;
if (this.username !== undefined && this.password !== undefined) {
// Set up server that requires http digest authentication
var httpdigest = require('./http-digest');
self.server = httpdigest.createServer(this.username, this.password,
function(req, res) { self.route(req, res); });
var configuredUsername = this.username;
var configuredPassword = this.password;
var auth = require('http-auth');
var crypto = require('crypto');

var digest = auth.digest({ realm: "webrepl" },
function (username, callback) { // Expecting md5(username:realm:password) in callback.
if (username === configuredUsername) {
var md5hash = crypto.createHash('md5');
callback(md5hash.update(configuredUsername + ":webrepl:" + configuredPassword).digest("hex"));
} else {
callback();
}
}
);

self.server = http.createServer(digest, function(req, res) {
self.route(req, res);
});
self.server.listen(port, this.hostname);
} else {
// No auth required
Expand Down

0 comments on commit 951f588

Please sign in to comment.