Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

casbin

Package Overview
Dependencies
Maintainers
3
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS

  • 3.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
63K
increased by5.07%
Maintainers
3
Weekly downloads
 
Created
Source

node-Casbin

NPM version NPM download install size codebeat badge Build Status Coverage Status Release Gitter

News: still worry about how to write the correct node-Casbin policy? Casbin online editor is coming to help! Try it at: http://casbin.org/en/editor/

casbin Logo

node-Casbin is a powerful and efficient open-source access control library for Node.JS projects. It provides support for enforcing authorization based on various access control models.

All the languages supported by Casbin:

golangjavanodejsphp
CasbinjCasbinnode-CasbinPHP-Casbin
production-readyproduction-readyproduction-readyproduction-ready
pythondotnetdelphirust
PyCasbinCasbin.NETCasbin4DCasbin-RS
production-readyproduction-readyexperimentalWIP

Installation

npm install casbin --save

Get started

  1. Initialize a new node-Casbin enforcer with a model file and a policy file:

    import casbin from 'casbin';
    const enforcer = await casbin.newEnforcer('path/to/model.conf', 'path/to/policy.csv');
    

    Note: you can also initialize an enforcer with policy in DB instead of file, see Persistence section for details.

  2. Add an enforcement hook into your code right before the access happens:

    const sub = 'alice'; // the user that wants to access a resource.
    const obj = 'data1'; // the resource that is going to be accessed.
    const act = 'read'; // the operation that the user performs on the resource.
    
    const res = await enforcer.enforce(sub, obj, act);
    if (res) {
      // permit alice to read data1
    } else {
      // deny the request, show an error
    }
    
  3. Besides the static policy file, node-Casbin also provides API for permission management at run-time. For example, You can get all the roles assigned to a user as below:

    const roles = enforcer.getRolesForUser('alice');
    

    See Policy management APIs for more usage.

  4. Please refer to the src/test package for more usage.

Policy management

Casbin provides two sets of APIs to manage permissions:

  • Management API: the primitive API that provides full support for Casbin policy management.
  • RBAC API: a more friendly API for RBAC. This API is a subset of Management API. The RBAC users could use this API to simplify the code.

We also provide a web-based UI for model management and policy management:

model editor

policy editor

Policy persistence

https://casbin.org/docs/en/adapters

Documentation

https://casbin.org/docs/en/overview

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

This project is licensed under the Apache 2.0 license.

Contact

If you have any issues or feature requests, please contact us. PR is welcomed.

FAQs

Package last updated on 29 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc