auth-rbac
v1.0.0
Published
RBAC-based authorization library for node
Downloads
47
Maintainers
Readme
auth-rbac
RBAC-based authorization library for node
Installation
$ npm install auth-rbac
Sample Usage
var authRbac = require('auth-rbac');
var express = require('express');
var User = require('./models/user');
var Role = require('./models/role');
var auth = authRbac({
getUser: function(req, cb) {
cb(null, req.user);
},
userGetRole: function(user, cb) {
Role.findById(user.role, cb);
},
roleHasPrivilege: function(role, priv, cb) {
cb(null, role.privileges.indexOf(priv) !== -1);
},
});
var app = express();
app.use(authRbac.identify(auth));
app.get('/users',
authRbac.requirePrivilege('user:enum')
function(req, res) {
return res.sendStatus(200);
});