https://github.com/http-auth/http-auth-koa
Koa framework integration with http-auth module.
https://github.com/http-auth/http-auth-koa
koa koa-framework
Last synced: 4 months ago
JSON representation
Koa framework integration with http-auth module.
- Host: GitHub
- URL: https://github.com/http-auth/http-auth-koa
- Owner: http-auth
- License: mit
- Created: 2016-06-17T22:36:07.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T10:32:45.000Z (over 1 year ago)
- Last Synced: 2025-06-12T09:50:37.460Z (5 months ago)
- Topics: koa, koa-framework
- Language: JavaScript
- Homepage:
- Size: 225 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# http-auth-koa
[Koa framework](http://koajs.com/) integration with [http-auth](https://github.com/gevorg/http-auth) module.
[](https://github.com/http-auth/http-auth-koa/actions/workflows/build.yml)
## Installation
Via git (or downloaded tarball):
```bash
$ git clone git://github.com/http-auth/http-auth-koa.git
```
Via [npm](http://npmjs.org/):
```bash
$ npm install http-auth-koa
```
## Usage
```javascript
// 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](https://mochajs.org/), so just run following command in package directory:
```bash
$ npm test
```
## License
The MIT License (MIT)