http-auth

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

MIT 105 个版本
安装
npm install http-auth
yarn add http-auth
pnpm add http-auth
bun add http-auth
README

http-auth

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

build

Installation

Via git (or downloaded tarball):

$ git clone git@github.com:gevorg/http-auth.git

Via npm:

$ npm install http-auth

Usage

// HTTP module
const http = require("http");

// Authentication module.
const auth = require("http-auth");
const basic = auth.basic({
  realm: "Simon Area.",
  file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass
});

// Creating new HTTP server.
http
  .createServer(
    basic.check((req, res) => {
      res.end(`Welcome to private area - ${req.user}!`);
    })
  )
  .listen(1337, () => {
    // Log URL.
    console.log("Server running at http://127.0.0.1:1337/");
  });

Please check examples directory for more.

Configurations

  • realm - Authentication realm, by default it is Users.
  • file - File where user details are stored.
    • Line format is {user:pass} or {user:passHash} for basic access.
    • Line format is {user:realm:passHash} for digest access.
    • Using a callback, it needs to return the same line format, example: file: () => 'adam:adam\neve:eve',
  • algorithm - Algorithm that will be used only for digest access authentication.
    • MD5 by default.
    • MD5-sess can be set.
  • qop - Quality of protection that is used only for digest access authentication.
    • auth is set by default.
    • none this option is disabling protection.
  • msg401 - Message for failed authentication 401 page.
  • msg407 - Message for failed authentication 407 page.
  • contentType - Content type for failed authentication page.
  • skipUser - Set this to true, if you don't want req.user to be filled with authentication info.
  • proxy - Set this to true, if you want to use it with http-proxy.

Running tests

It uses mocha, so just run following command in package directory:

$ npm test

Questions

You can also use stackoverflow to ask questions using http-auth tag.

Utilities

  • htpasswd - Node.js package for HTTP Basic Authentication password file utility.
  • htdigest - Node.js package for HTTP Digest Authentication password file utility.

Integrations

Please check this link for integration packages.

License

The MIT License (MIT)

版本列表
4.2.1 2025-05-02
4.2.0 2022-09-21
4.1.9 2021-08-10
4.1.7 2021-06-24
4.1.6 2021-06-24
4.1.5 2021-04-09
4.1.4 2021-03-17
4.1.3 2021-03-14
4.1.2 2020-02-03
4.1.1 2020-02-02
4.1.0 2020-02-02
4.0.2 2020-02-02
4.0.1 2020-02-02
4.0.0 2020-02-02
3.2.4 2019-10-02
3.2.3 2017-07-08
3.1.3 2017-03-07
3.1.2 2017-03-07
3.1.1 2016-11-20
3.1.0 2016-11-10
3.0.1 2016-10-24
3.0.0 2016-10-18
2.4.11 2016-10-18
2.4.10 2016-09-08
2.4.9 2016-09-07
2.4.8 2016-09-05
2.4.7 2016-09-02
2.4.6 2016-09-02
2.4.5 2016-09-02
2.4.4 2016-06-18
2.4.3 2016-06-18
2.4.2 2016-06-18
2.4.1 2016-06-12
2.4.0 2016-06-12
2.3.9 2016-06-07
2.3.8 2016-06-06
2.3.7 2016-06-04
2.3.6 2016-05-13
2.3.5 2016-05-13
2.3.4 2016-05-13
2.3.3 2016-04-23
2.3.2 2016-04-23
2.3.1 2016-04-13
2.3.0 2016-04-13
2.2.9 2016-04-01
2.2.8 2015-06-04
2.2.7 2015-06-01
2.2.6 2015-05-26
2.2.5 2014-12-15
2.2.4 2014-12-02
2.2.3 2014-11-28
2.2.2 2014-11-28
2.2.1 2014-11-25
2.2.0 2014-09-12
2.1.9 2014-07-31
2.1.8 2014-06-06
2.1.7 2014-03-20
2.1.6 2014-02-10
2.1.5 2014-01-17
2.1.4 2014-01-12
2.1.3 2014-01-03
2.1.2 2013-12-28
2.1.1 2013-12-28
2.1.0 2013-12-27
2.0.9 2013-12-03
2.0.8 2013-11-27
2.0.7 2013-10-29
2.0.6 2013-10-14
2.0.5 2013-10-07
2.0.4 2013-09-07
2.0.3 2013-09-07
2.0.2 2013-09-07
2.0.1 2013-09-07
2.0.0 2013-09-06
1.3.0 2013-09-04
1.2.9 2013-08-28
1.2.8 2013-08-23
1.2.7 2013-01-25
1.2.6 2013-01-23
1.2.5 2013-01-10
1.2.4 2012-12-10
1.2.3 2012-11-24
1.2.2 2012-04-28
1.2.1 2012-03-27
1.2.0 2012-03-25
1.1.9 2012-01-29
1.1.8 2012-01-28
1.1.7 2012-01-28
1.1.6 2012-01-25
1.1.5 2012-01-15
1.1.4 2011-12-04
1.1.3 2011-12-04
1.1.2 2011-12-04
1.1.1 2011-12-04
1.1.0 2011-12-03
1.0.9 2011-11-28
1.0.8 2011-10-08
1.0.7 2011-10-07
1.0.6 2011-10-06
1.0.5 2011-10-04
1.0.4 2011-10-04
1.0.3 2011-09-29
1.0.2 2011-09-29
1.0.1 2011-09-29
1.0.0 2011-09-18