3.1.1 • Published 4 years ago

basicauth-middleware v3.1.1

Weekly downloads
10,733
License
MIT
Repository
github
Last release
4 years ago

basicauth-middleware

Express js basicauth middleware

Installation

npm install basicauth-middleware --save

Usage

const app = express();
const basicauth = require('basicauth-middleware');

// Using plain username and password
app.use(basicauth('username', 'password'));

// Using plain username and password with custom realm
app.use(basicauth('username', 'password', 'Secrets Within!'));

// Using an array of username and password
app.use(basicauth([['username', 'password'], ['username2', 'password2']]);

// Using sync callback
app.use(basicauth((username, password) => {
    // Your check function
    const auth = checkAuth();

    return auth;
}, 'custom optional realm'));

// Using node style async callback
app.use(basicauth((username, password, cb) => {
    // Your check function
    const auth = checkAuth();

    cb(null, auth);
}, 'custom optional realm'));

// Using Promise
app.use(basicauth((username, password) => {
    // Your check function
    return checkAuth(username, password).then(() => {
      return true;
    });
}, 'custom optionnal realm'));

// Or async/await function
app.use(basicauth(async (username, password) => {
    // Your check function
    await checkAuth(username, password);

    return true;
}, 'custom optionnal realm'));

Test

npm run test
3.1.1

4 years ago

3.1.0

6 years ago

3.0.0

7 years ago

2.0.0

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

9 years ago

0.0.1

9 years ago