koa-oai-router-acl
v1.0.0
Published
acl plugin of koa-oai-router
Downloads
3
Maintainers
Readme
Koa-OAI-Router-ACL
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());