Skip to content

Koa framework integration with http-auth module.

License

Notifications You must be signed in to change notification settings

http-auth/http-auth-koa

Repository files navigation

http-auth-koa

Koa framework integration with http-auth module.

build

Installation

Via git (or downloaded tarball):

$ git clone git://github.com/http-auth/http-auth-koa.git

Via npm:

$ npm install http-auth-koa

Usage

// Authentication module.
const auth = require("http-auth");
const koaAuth = require("http-auth-koa");

const basic = auth.basic({
  realm: "Simon Area.",
  file: __dirname + "/../data/users.htpasswd"
});

// Koa setup.
const Koa = require("koa");
const app = new Koa();

// Setup basic handler.
app.use(async (ctx, next) => {
  await next();
  ctx.body = `Welcome to koa ${ctx.req.user}!`;
});

// Setup auth.
app.use(koaAuth(basic));

// Start server.
app.listen(1337, function() {
  // Log URL.
  console.log("Server running at http://127.0.0.1:1337/");
});

Running tests

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

$ npm test

License

The MIT License (MIT)