Apache Casbin (Incubating) is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Apache Incubator PMC.
Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.
While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
Earlier package publications form the legacy Casbin community release history. Their presence in a registry does not establish Apache release approval. Apache releases require project and Incubator approval of the exact source distribution.
News: still worry about how to write the correct node-casbin policy? Casbin online editor is coming to help!
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.
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| Casbin | jCasbin | node-Casbin | PHP-Casbin |
| production-ready | production-ready | production-ready | production-ready |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| PyCasbin | Casbin.NET | Casbin-CPP | Casbin-RS |
| production-ready | production-ready | beta-test | production-ready |
https://casbin.apache.org/docs/overview
# NPM
npm install apache-casbin --save
# Yarn
yarn add apache-casbinNew a node-casbin enforcer with a model file and a policy file, see Model section for details:
// For Node.js:
const { newEnforcer } = require('apache-casbin');
// For browser:
// import { newEnforcer } from 'apache-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 section for details.
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.
// 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:
const roles = await enforcer.getRolesForUser('alice');See Policy management APIs for more usage.
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.
https://casbin.apache.org/docs/supported-models
https://casbin.apache.org/docs/adapters
https://casbin.apache.org/docs/watchers
https://casbin.apache.org/docs/role-managers
This project exists thanks to all the people who contribute.
This project is licensed under the Apache 2.0 license.
If you have any issues or feature requests, please contact us. PR is welcomed.
The runtime dependency supports Node.js 20 or 22 and later. Build and development tools require a current Node.js 20 LTS release or later.
The next approved distribution uses apache-casbin in place of the historical npm package casbin. The API is unchanged by the name migration. After the approved package is published, update dependency declarations and imports to apache-casbin, regenerate your lockfile and check that adapters use the same core package instance. Existing casbin releases remain available; updating that old dependency does not automatically switch packages. Do not install both core identities in one application. Candidates are for review, not installation from npm.








