Coder Social home page Coder Social logo

meepobrother / node-casbin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from casbin/node-casbin

0.0 1.0 0.0 727 KB

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

Home Page: https://casbin.org/

License: Apache License 2.0

JavaScript 0.12% TypeScript 99.88%

node-casbin's Introduction

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:

golang java nodejs php
Casbin jCasbin node-Casbin PHP-Casbin
production-ready production-ready production-ready production-ready
python dotnet delphi rust
PyCasbin Casbin.NET Casbin4D Casbin-RS
production-ready production-ready experimental WIP

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.

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.

node-casbin's People

Contributors

hsluoyz avatar nodece avatar snowliy avatar calebfaruki avatar ghaiklor avatar szy0syz avatar rictorres avatar devsatishm avatar zuohuadong avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.