koa-acl
acl middleware for koa
Last updated 2 years ago by jackong .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install koa-acl 
SYNC missed versions from official npm registry.

ACL middleware for koa.

NPM version build status David deps node version Gittip

Features

  • More smart to adapt koa.

Document

Examples

Setting options.

var ACL = require('koa-acl');
var Acl = require('acl');
app.use(
    ACL({
        //user getter
        user: function(ctx) {
            return ctx.state.user._id;
        },
        //backend getter
        backend: new Acl.memoryBackend()
    })
);

Middleware for users or roles.

var ACL = require('koa-acl');
route.delete(
    '/api/users/:user',
    ACL.middleware(2),
    function* (next) {
        //do something...
    }
);

Methods

Acl(options)

Configure options for Acl.

Arguments

options.user    {Function} user ID getter.
options.backend {Object|Function} backend getter.


Acl.middleware(numPathComponents[, userId, actions])

Authorizing by user.

Arguments

numPathComponents   {Number}    number of components in the url to be considered part of the resource name (defaults to number of components in the full url).
userId {String|Function}   user ID (defaults to options.user).
actions {String|Array}    lowercase.

Tests

npm test

Licences

MIT

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |