Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/casbin/node-casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser
https://github.com/casbin/node-casbin
abac access-control acl auth authorization authz casbin javascript js node nodejs permission permissions rbac
Last synced: 24 days ago
JSON representation
An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser
- Host: GitHub
- URL: https://github.com/casbin/node-casbin
- Owner: casbin
- License: apache-2.0
- Created: 2018-07-15T03:55:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-10T17:34:16.000Z (7 months ago)
- Last Synced: 2024-04-14T11:00:44.679Z (7 months ago)
- Topics: abac, access-control, acl, auth, authorization, authz, casbin, javascript, js, node, nodejs, permission, permissions, rbac
- Language: TypeScript
- Homepage: https://casbin.org
- Size: 2.89 MB
- Stars: 2,468
- Watchers: 20
- Forks: 209
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome - casbin/node-casbin - An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser (TypeScript)
- awesome-nodejs-cn - node-casbin - 支持访问控制模型(如 ACL、RBAC 和 ABAC )的授权库 (包 / 授权)
- awesome-nodejs - node-casbin - Authorization library that supports access control models like ACL, RBAC and ABAC. ![](https://img.shields.io/github/stars/casbin/node-casbin.svg?style=social&label=Star) (Repository / Authorization)
- awesome-web-cn - node-casbin - 一个 node 的权限管理库,支持 ACL , RBAC , ABAC 等访问控制模型的库 (Uncategorized / Uncategorized)
- awesome-nodejs-cn - node-casbin - **star:2516** 支持ACL、RBAC和ABAC等访问控制模型的授权库 ![star > 2000][Awesome] (包 / 授权)
- awesome-nestjs - node-casbin - 支持 ACL, RBAC, ABAC 权限管理的 Nodejs 库 (资源 / 集成)
- awesome-nodejs - node-casbin - Authorization library that supports access control models like ACL, RBAC and ABAC. (Packages / Authorization)
- awesome-auth - Node-Casbin - Authorization library that supports access control models like ACL, RBAC, ABAC in Node.js. (Authorization / <a name="authZ-node"></a>Node.js)
- awesome-authentication - AuthZ lib supports ACL, RBAC, ABAC in Node.js
- awesome-nodejs - node-casbin - An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js - ★ 192 (Authorization)
- awesome-node - node-casbin - Authorization library that supports access control models like ACL, RBAC and ABAC. (Packages / Authorization)
- awesome-nodejs-cn - node-casbin - 支持访问控制模型(如ACL、RBAC和ABAC)的授权库. (目录 / 授权库)
- awesome - casbin/node-casbin - An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser (TypeScript)
README
# Node-Casbin
[![NPM version][npm-image]][npm-url]
[![NPM download][download-image]][download-url]
[![install size](https://packagephobia.now.sh/badge?p=casbin)](https://packagephobia.now.sh/result?p=casbin)
[![codebeat badge](https://codebeat.co/badges/c17c9ee1-da42-4db3-8047-9574ad2b23b1)](https://codebeat.co/projects/github-com-casbin-node-casbin-master)
[![GitHub Actions](https://github.com/casbin/node-casbin/workflows/main/badge.svg)](https://github.com/casbin/node-casbin/actions)
[![Coverage Status](https://coveralls.io/repos/github/casbin/node-casbin/badge.svg?branch=master)](https://coveralls.io/github/casbin/node-casbin?branch=master)
[![Release](https://img.shields.io/github/release/casbin/node-casbin.svg)](https://github.com/casbin/node-casbin/releases/latest)
[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)[npm-image]: https://img.shields.io/npm/v/casbin.svg?style=flat-square
[npm-url]: https://npmjs.org/package/casbin
[download-image]: https://img.shields.io/npm/dm/casbin.svg?style=flat-square
[download-url]: https://npmjs.org/package/casbin
Sponsored by
Build auth with fraud prevention, faster.
Try Stytch for API-first authentication, user & org management, multi-tenant SSO, MFA, device fingerprinting, and more.
💖 [**Looking for an open-source identity and access management solution like Okta, Auth0, Keycloak ? Learn more about: Casdoor**](https://casdoor.org/)
**News**: still worry about how to write the correct `node-casbin` policy? [Casbin online editor](http://casbin.org/editor) is coming to help!
![casbin Logo](casbin-logo.png)
`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](https://wikipedia.org/wiki/Computer_security_model).
## All the languages supported by Casbin:
| [![golang](https://casbin.org/img/langs/golang.png)](https://github.com/casbin/casbin) | [![java](https://casbin.org/img/langs/java.png)](https://github.com/casbin/jcasbin) | [![nodejs](https://casbin.org/img/langs/nodejs.png)](https://github.com/casbin/node-casbin) | [![php](https://casbin.org/img/langs/php.png)](https://github.com/php-casbin/php-casbin) |
| -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| [Casbin](https://github.com/casbin/casbin) | [jCasbin](https://github.com/casbin/jcasbin) | [node-Casbin](https://github.com/casbin/node-casbin) | [PHP-Casbin](https://github.com/php-casbin/php-casbin) |
| production-ready | production-ready | production-ready | production-ready || [![python](https://casbin.org/img/langs/python.png)](https://github.com/casbin/pycasbin) | [![dotnet](https://casbin.org/img/langs/dotnet.png)](https://github.com/casbin-net/Casbin.NET) | [![c++](https://casbin.org/img/langs/cpp.png)](https://github.com/casbin/casbin-cpp) | [![rust](https://casbin.org/img/langs/rust.png)](https://github.com/casbin/casbin-rs) |
| ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- |
| [PyCasbin](https://github.com/casbin/pycasbin) | [Casbin.NET](https://github.com/casbin-net/Casbin.NET) | [Casbin-CPP](https://github.com/casbin/casbin-cpp) | [Casbin-RS](https://github.com/casbin/casbin-rs) |
| production-ready | production-ready | beta-test | production-ready |## Documentation
https://casbin.org/docs/overview
## Installation
```shell script
# NPM
npm install casbin --save# Yarn
yarn add casbin
```## Get started
New a `node-casbin` enforcer with a model file and a policy file, see [Model](#official-model) section for details:
```node.js
// For Node.js:
const { newEnforcer } = require('casbin');
// For browser:
// import { newEnforcer } from 'casbin';const enforcer = await newEnforcer('basic_model.conf', 'basic_policy.csv');
```> **Note**: you can also initialize an enforcer with policy in DB instead of file, see [Persistence](#policy-persistence) section for details.
Add an enforcement hook into your code right before the access happens:
```node.js
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.// Async:
const res = await enforcer.enforce(sub, obj, act);
// Sync:
// const res = enforcer.enforceSync(sub, obj, act);if (res) {
// permit alice to read data1
} else {
// deny the request, show an error
}
```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:```node.js
const roles = await enforcer.getRolesForUser('alice');
```See [Policy management APIs](#policy-management) for more usage.
## Policy management
Casbin provides two sets of APIs to manage permissions:
- [Management API](https://casbin.org/docs/management-api): the primitive API that provides full support for Casbin policy management.
- [RBAC API](https://casbin.org/docs/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.## Official Model
https://casbin.org/docs/supported-models
## Policy persistence
https://casbin.org/docs/adapters
## Policy consistence between multiple nodes
https://casbin.org/docs/watchers
## Role manager
https://casbin.org/docs/role-managers
## Contributors
This project exists thanks to all the people who contribute.
## Backers
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/casbin#backer)]
## Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/casbin#sponsor)]
## License
This project is licensed under the [Apache 2.0 license](LICENSE).
## Contact
If you have any issues or feature requests, please contact us. PR is welcomed.
- https://github.com/casbin/node-casbin/issues
- [email protected]
- Tencent QQ group: [546057381](//shang.qq.com/wpa/qunwpa?idkey=8ac8b91fc97ace3d383d0035f7aa06f7d670fd8e8d4837347354a31c18fac885)