Koa-ACL-Swagger
NOTICE: can not be used in production
a role base access controller and working with swagger (named OpenAPI now)
In YAML file, add x-resource
option to each path. when a user visit this url, the middleware will check the permission based on resource name and HTTP method. like "user test-user
have the permission post
of the resource pets
". so you should set role-base permission before.
see demo in examples/app
Install
Node.js >= 6.x && Koa >= 2.x
npm install koa-acl-swagger
Usage
const app = const acl = store: type: 'redis' client: aclStore prefix: 'examples:app:' getUserId: async { return 'test' } api: dir: path skip: 1 // init permissions by acl// .... app app
Class
AclSwagger
params
storetype string database type redis | mongodb | memory can be used default: memoryclient object database clientprefix string saved prefixgetUserId async-
Methods
getMiddleware()
return a middleware for koa@2.x
Acl module Async function
convert acl module functions to async style (translate by bulebird). like addUserRolesAsync
allowAsync
isAllowedAsync
...
allRolesAsync()
return all roles (async style)
removeUserAllRolesAsync(userId)
remove all roles from a given user (async style), and return true if removed