Socket
Socket
Sign inDemoInstall

basicauth-middleware

Package Overview
Dependencies
2
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    basicauth-middleware

Express js basic auth middleware


Version published
Maintainers
1
Install size
44.7 kB
Created

Changelog

Source

3.1.1

  • upgrade dependencies
  • remove node < 10 support

Readme

Source

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

FAQs

Last updated on 16 Mar 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc