https://github.com/emartech/koa-escher-auth
https://github.com/emartech/koa-escher-auth
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/emartech/koa-escher-auth
- Owner: emartech
- License: mit
- Created: 2016-01-26T12:31:09.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-01-26T09:20:36.000Z (over 3 years ago)
- Last Synced: 2025-06-29T06:39:36.345Z (about 1 year ago)
- Language: JavaScript
- Size: 472 KB
- Stars: 0
- Watchers: 16
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-escher-auth
[](https://david-dm.org/emartech/koa-escher-auth)
[](https://david-dm.org/emartech/koa-escher-auth#info=devDependencies)
This koa middleware allows you to restrict access to pages with Escher authentication.
## Usage
The middlewares will work only in the following order:
1. A bodyparser defining rawBody on the request (e.g. koa-bodyparser)
2. Authenticator middleware (lib/koa-authenticator)
```javascript
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const escherAuth = require('koa-escher-auth');
let escherConfig = {
credentialScope: 'eu/app-id/ems_request',
keyPool: JSON.stringify([
{ 'keyId': 'app-id_suite_v1', 'secret': 'app-id-secret', acceptOnly: 0 }
])
};
let app = new Koa();
app.use(bodyParser());
app.use(escherAuth.authenticator(escherConfig));
app.use(function(ctx) {
ctx.body = `Hello world, ${ctx.escherAccessKeyId}!`;
});
```
The access key id used to authenticate the request will be available on the context as `escherAccessKeyId`
### Environment variables
If you define SUITE_ESCHER_CREDENTIAL_SCOPE and SUITE_ESCHER_KEY_POOL as environment variables
the setup becomes even more easier.
```
SUITE_ESCHER_CREDENTIAL_SCOPE='eu/app-id/ems_request'
SUITE_ESCHER_KEY_POOL='[{"keyId": "app-id_suite_v1", "secret": "app-id-secret", "acceptOnly": 0}]'
```
```javascript
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const escherAuth = require('koa-escher-auth');
let app = new Koa();
app.use(bodyParser());
app.use(escherAuth.authenticator());
app.use(function(ctx) {
ctx.body = 'Hello world';
});
```
### Notes
The keypool always has to be a valid JSON string.
You are able to add other middlewares between bodyparser and authenticator if you want.