• Stars
    star
    968
  • Rank 47,266 (Top 1.0 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hierarchical Role Based Access Control for NodeJS

RBAC

(Hierarchical Role Based Access Control)

NPM version build status Test coverage Gitter chat

RBAC is the authorization library for NodeJS.

πŸŽ‰ We have supported DynamoDB storage now by implementation of dynamoose.

Motivation

I needed hierarchical role based access control for my projects based on ExpressJS. I had one requirement. This structure must be permanently stored in various storages. For example in memory or Mongoose. Because there is a lot of options for storing of data and many of them are asynchronous. I created asynchronous API. Please, if you found any bug or you need custom API, create an issue or pull request.

Documentation

Read more about API in documentation

Support us

Star this project on GitHub.

Install

npm install rbac

Usage

import { RBAC } from 'rbac'; // ES5 var RBAC = require('rbac').default;
const rbac = new RBAC({
  roles: ['superadmin', 'admin', 'user', 'guest'],
  permissions: {
    user: ['create', 'delete'],
    password: ['change', 'forgot'],
    article: ['create'],
    rbac: ['update'],
  },
  grants: {
    guest: ['create_user', 'forgot_password'],
    user: ['change_password'],
    admin: ['user', 'delete_user', 'update_rbac'],
    superadmin: ['admin'],
  },
});

await rbac.init();

Usage with express

import express from 'express';
import { RBAC } from 'rbac';
import secure from 'rbac/controllers/express';

// your custom controller for express
function adminController(req, res, next) {
  res.send('Hello admin');
}

const app = express();
const rbac = new RBAC({
  roles: ['admin', 'user'],
});

await rbac.init();

// setup express routes
app.use('/admin', secure.hasRole(rbac, 'admin'), adminController);

Check permissions

const can = await rbac.can('admin', 'create', 'article');
if (can) {
  console.log('Admin is able create article');
}

// or you can use instance of admin role
const admin = await rbac.getRole('admin');
if (!admin) {
  return console.log('Role does not exists');
}

const can = await admin.can('create', 'article');
if (can) {
  console.log('Admin is able create article');    
}

Mongoose user model

Please take a look on plugin mongoose-hrbac

Build documentation

npm run doc

Running Tests

npm run test

Build

npm run build

Credits

License

The MIT License (MIT)

Copyright (c) 2016-2018 Zlatko Fedor [email protected]

More Repositories

1

react-facebook

Facebook components like a Login button, Like, Share, Chat, Comments, Page or Embedded Post
TypeScript
771
star
2

react-g-analytics

React google analytics with support for react-router
JavaScript
116
star
3

angular-es6

Angular ES6 utility library. Write directives, controllers and services as ES6 classes.
JavaScript
101
star
4

react-google-publisher-tag

Adsense via Google publisher tag for universal applications
JavaScript
93
star
5

mongoose-hrbac

Hierarchical Role Based Access Control for your mongoose models
JavaScript
60
star
6

react-form-controlled

Intuitive react forms for building powerful applications.
JavaScript
52
star
7

kysely-orm

TypeSafe ORM for Kysely library
TypeScript
34
star
8

goodmodule

JavaScript tips (ES6, CSS, Benchmarks, React, Redux, ...)
32
star
9

maglev

Preconfigured simple NodeJS framework
JavaScript
18
star
10

react-high-order-provider

Create your react high-order component easily
JavaScript
8
star
11

livia

Universal database driver with support of schemas
JavaScript
7
star
12

orientose

Orientose is a OrientDB object modeling with support of schemas inspired by mongoose.
JavaScript
6
star
13

fast-wait

Delay a promise a specified amount of time. Always fast as possible.
JavaScript
5
star
14

react-strike

Strike component for the React
JavaScript
4
star
15

react-spinner-children

A React component wrapper for spin.js with support for children
JavaScript
4
star
16

react-provide-props

Create react higher-order components simply
JavaScript
4
star
17

mongoose-geojson

Mongoose GEO JSON
JavaScript
3
star
18

livia-orientdb

Orientdb adapter for universal database driver Livia
JavaScript
3
star
19

ember-require-resolver

Universal simply extendable ember resolver
JavaScript
3
star
20

graceful-close

Close node 6+ server gracefully with timeout support.
JavaScript
3
star
21

mongoose-locale

JavaScript
2
star
22

class-extender

Simple class inheritance
JavaScript
2
star
23

react-renderify

Get async response from your component.
TypeScript
2
star
24

react-router-provider

Provide router as property to any component
JavaScript
2
star
25

ember-datalight

A lightweight data persistence library for Ember with full support of JSON structure
JavaScript
2
star
26

web-error

Custom error object with code of http error
JavaScript
2
star
27

async-sync

Safe async utilities for node and the browser
JavaScript
2
star
28

mongoose-storage

Simple storage service for files.
JavaScript
2
star
29

better-timeout

Standard javascript timeout with clearTimeout as returned function
JavaScript
2
star
30

react-neutral

Basic react components working on the web and react-native
JavaScript
2
star
31

react-form-controlled-validate

Validation of the forms. High order components for react-form-controlled
JavaScript
2
star
32

mongoose-permalink

Create automatically slug permalink in your mongoose models
JavaScript
2
star
33

react-instagram

Instagram components
1
star
34

canvas-paper

Isomorphic canvas layers
JavaScript
1
star
35

mongoose-address

Mongoose address
JavaScript
1
star
36

react-cdn

Image resize by CDN
1
star
37

base-error

Base Error
JavaScript
1
star
38

react-linkedin

LinkedIn components
1
star
39

react-amazon

Amazon components
1
star
40

react-twitter

Twitter components
1
star
41

is-development

Detect if you are in the development mode of the nodejs
JavaScript
1
star
42

router-execute-action-provider

Provide fluxible`s executeAction into the compoment with third parameter redirecting user via react-router
JavaScript
1
star
43

fluxible-provider

Provide executeAction and getStore to your component
JavaScript
1
star
44

react-braintree

Braintree components
1
star
45

react-google

Google components
1
star
46

mongoose-nestedset

Nested set for mongoose models
JavaScript
1
star
47

stylex-ui

StyleX UI component library for React Native & Web
1
star