Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

basic-authentication

hex7c06kApache-2.01.10.0

http basic authentication

basic, basic-auth, authentication, authorization

readme

basic-authentication

NPM version Linux Status Windows Status Dependency Status Coveralls

Basic authentication is method for a HTTP user agent to provide a user name and password.

Installation

Install through NPM

npm install basic-authentication

or

git clone git://github.com/hex7c0/basic-authentication.git

API

inside expressjs project like a middleware

var authentication = require('basic-authentication')();

var app = require('express')();
app.use(authentication);

inside expressjs project like a callback for certain route

var authentication = require('basic-authentication')();

var app = require('express')();
app.get('/', authentication, function(req, res) {

    res.send('ok');
});

inside routing like a function

var authentication = require('basic-authentication')({functions: true});

var app = require('express')();
app.get('/', function(req, res) {

    var user = authentication(req);
    if (user == 'foo') {
        res.send('ok');
    } else {
        res.send('ko');
    }
});

authentication(options)

options

  • user - String User for web basic access authentication (default "admin")
  • password - String Password for web basic access authentication (default "password")
  • file - String Path of htpasswd file (default "disabled")
  • hash - String Type of hash inside your htpasswd file (default "md5")
  • agent - String Browser User Agent for web authentication (default "all accepted")
  • realm - String Realm for web authentication (default "Authorization required")
  • ending - Boolean Flag for send res.end (response) to client after error or wrong password (not in "functions" mode) (default "true")
  • functions - Boolean Flag for using module like a function (default "false")
  • legacy - Boolean Flag for using module like a function that return an Object (default "false")
  • suppress - Boolean Suppress all routing error (default "false")

in functions mode, it return a Base64 String; otherwise, if some errors occurred, return an Empty String

in legacy mode, it return an Object {user, password}; otherwise, if some errors occurred, return an Empty Object

Examples

Take a look at my examples

License Apache2

changelog

v1.10.0 / 2017-12-31

v1.9.0 / 2017-05-14

v1.8.0 / 2016-12-21

v1.7.0 / 2016-09-12

v1.6.2 / 2015-11-26

v1.6.1 / 2015-09-26

v1.6.0 / 2015-08-19

v1.5.12 / 2015-02-28

v1.5.11 / 2015-02-04

v1.5.10 / 2015-01-19

v1.5.9 / 2014-11-17

  • Strict check
  • Using setheaders

v1.5.8 / 2014-10-26

  • jshint

v1.5.7 / 2014-10-04

  • Remove jsdoc
  • package.json min

v1.5.5 / 2014-08-31

  • Avoid try-catch code

v1.5.4 / 2014-08-23

  • Performance tips

v1.5.2 / 2014-08-11

  • Update README.md

v1.5.1 / 2014-08-04

  • Doc update

v1.5.0 / 2014-07-27

  • Test "node": ">=0.10.0" only
  • Using task runner grunt
  • Using test framework mocha
  • Testing script will be put inside "test/"
  • ".npmignore" more aggressive
  • uglify compiles

v1.4.0 / 2014-07-25

  • Rewrite for multiple require

v1.3.3 / 2014-07-22

  • Fix with multiple require
  • Fix option.legacy

v1.3.1 / 2014-07-21

v1.3.0 / 2014-07-21

  • Ready for htpasswd file
  • Add 'file' and 'hash' (options)

v1.2.1 / 2014-07-20

  • Http Status Code
  • OR control flow

v1.2.0 / 2014-07-17

  • Code rewrite
  • Remove ugly parts
  • Little improvement with RegExp

v1.1.3 / 2014-06-29

  • Remove anonymous function
  • Update express @ 4.4.5

v1.1.1 / 2014-06-18

  • Doc updated

v1.1.0 / 2014-06-18

  • Slightly faster performance
  • Deprecated use of 'functions' with return Object

v1.0.2 / 2014-06-15

  • Error handling

v1.0.1 / 2014-06-15

  • Also ready for nodejs

v1.0.0 / 2014-06-14

  • Operative
  • Build with examples

v0.0.1 / 2014-06-13

  • Project start