http-auth-koa
Koa framework integration with http-auth module.
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
const auth = require("http-auth");
const koaAuth = require("http-auth-koa");
const basic = auth.basic({
realm: "Simon Area.",
file: __dirname + "/../data/users.htpasswd"
});
const Koa = require("koa");
const app = new Koa();
app.use(async (ctx, next) => {
await next();
ctx.body = `Welcome to koa ${ctx.req.user}!`;
});
app.use(koaAuth(basic));
app.listen(1337, function() {
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)