1.0.0 • Published 6 years ago

koa-oai-router-acl v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

Koa-OAI-Router-ACL

License Node Version NPM Version Build Status Test Coverage Downloads Dependency Status

ACL plugin koa-oai-router

Installation

npm i koa-oai-router-acl --save

Info

fieldtypeinfo
namestringacl
evoked fieldsstringx-oai-acl
evoked fileds valueobject{resource,permission}
optionsobjectacl, getUid, before, after
  • options {object}
  • acl {function} acl factory function. having args (Acl) and must return a acl instance.
  • getUid {function} get uid. having args (ctx) and must return a uid({string}).
  • before {function} handle before acl permission test. having args (ctx, next), next evoked will allow request.
  • after {function} handle after acl permission test. having args (ctx, next, allowed).

    const Koa = require('koa');
    const Router = require('koa-oai-router');
    const MiddlewarePlugin = require('koa-oai-router-middleware');
    const AclPlugin = require('koa-oai-router-acl');
    const Redis = require('ioredis');

const app = new Koa(); const router = new Router({ apiDoc: './api', options: { MiddlewarePlugin: './controllers', AclPlugin: { acl: async (Acl) => { const redis = new Redis({ keyPrefix: 'acl_test' });

    await new Promise((resolve, reject) => {
      redis.once('ready', resolve);
      redis.once('error', reject);
    });

    return new Acl(new Acl.redisBackend(redis));
  },
  uid: (ctx) => {
    // you uid code.
    return ctx.session.userId;
  },
},

}, });

router.mount(AclPlugin); router.mount(MiddlewarePlugin);

app.use(router.routes());