How to use the http-auth.digest function in http-auth

To help you get started, we’ve selected a few http-auth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mwittig / node-fronius-solar / test / server.js View on Github external
"Timestamp": "2019-08-09T07:59:05+02:00"
            }
        }));
    } else {
        console.log("404 Not Found");
        response.writeHead(404, {
            "Content-Type": "text/plain"
        });
        response.write("404 Not Found\n");
        response.end();
        return;
    }
}

if (useDigestAuth) {
    var digest = auth.digest({
        realm: realm
    }, function (username, callback) { // Expecting md5(username:realm:password) in callback.
        if (username === "admin") {
            var hash = crypto.createHash('md5');
            hash.update("admin:" + realm + ":admin");
            callback(hash.digest('hex'));
        } else {
            callback();
        }
    });
    http.createServer(digest, requestListener).listen(parseInt(port, 10));
} else {
    http.createServer(requestListener).listen(parseInt(port, 10));
}

console.log("Server running at\n  => http://localhost:" + parseInt(port, 10) + "/\nCTRL + C to shutdown");
github mmattozzi / webrepl / webrepl.js View on Github external
ReplHttpServer.prototype.start = function(port) {
    var self = this;
    if (this.username !== undefined && this.password !== undefined) {
        // Set up server that requires http digest authentication
        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
github JCMais / node-libcurl / test / curl / optionHttpAuth.spec.ts View on Github external
const url = `http://${host}:${port}/`

const username = 'user'
const password = 'pass'
const realmBasic = 'basic'
const realmDigest = 'digest'
const basic = auth.basic(
  {
    realm: realmBasic,
  },
  (usr, pass, callback) => {
    callback(usr === username && pass === password)
  },
)
const digest = auth.digest(
  {
    realm: realmDigest,
  },
  (usr, callback) => {
    const hash = crypto.createHash('md5')

    if (usr === username) {
      hash.update([username, realmDigest, password].join(':'))
      const hashDigest = hash.digest('hex')

      callback(hashDigest)
    } else {
      callback()
    }
  },
)

http-auth

Node.js package for HTTP basic and digest access authentication.

MIT
Latest version published 2 years ago

Package Health Score

58 / 100
Full package analysis