http-auth-koa

1.1.7 • Public • Published

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)

Package Sidebar

Install

npm i http-auth-koa

Weekly Downloads

13

Version

1.1.7

License

MIT

Unpacked Size

3.8 kB

Total Files

4

Last publish

Collaborators

  • gevorg