koa-oai-router-acl

1.0.0 • Public • Published

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

field type info
name string acl
evoked fields string x-oai-acl
evoked fileds value object {resource,permission}
options object acl, 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());

Package Sidebar

Install

npm i koa-oai-router-acl

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

8.77 kB

Total Files

12

Last publish

Collaborators

  • bitebit