Giter Site home page Giter Site logo

koa-escher-auth's Introduction

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.

koa-escher-auth's People

Contributors

andrasp3a avatar bankyadam avatar boogie avatar burci avatar drawain avatar gergaczd avatar jzsfkzm avatar knagy avatar peter-vasarhelyi avatar qw3r avatar sonicoder86 avatar szeist avatar szenti avatar tt1991 avatar wilzi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.