koa-http-basic-auth

HTTP basic auth middleware for koa.


Keywords
basic-authentication, http, koa, middleware, nodejs
License
MIT
Install
npm install koa-http-basic-auth@1.0.2

Documentation

koa-http-basic-auth

Installation

npm

npm install --save koa-http-basic-auth

yarn

yarn add koa-http-basic-auth

Usage

const Koa = require('koa');
const basicAuth = require('koa-http-basic-auth');

const app = new Koa();

// Register koa-http-basic-auth middleware
app.use(basicAuth({
  user: 'username', // required
  pass: 'password', // required
  realm: 'Authorization', // optional, defaults to 'Authorization required'
}));

// Protected response
app.use(async (ctx) => {
  ctx.status(200);
  ctx.body = 'Protected';
});

app.listen(3000);