4.0.0 • Published 1 year ago

koa-escher-auth v4.0.0

Weekly downloads
292
License
MIT
Repository
github
Last release
1 year ago

koa-escher-auth

Dependency Status devDependency Status

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)

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}]'
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.

4.0.0

1 year ago

3.5.0

1 year ago

3.4.0

3 years ago

3.3.0

3 years ago

3.2.0

4 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.5.4

6 years ago

2.5.3

7 years ago

2.5.2

7 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.2

7 years ago

2.4.1

8 years ago

2.4.0

8 years ago

2.3.0

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago

0.0.1

8 years ago