![]() |
VOOZH | about |
dotnet add package Casbin.NET --version 2.21.2
NuGet\Install-Package Casbin.NET -Version 2.21.2
<PackageReference Include="Casbin.NET" Version="2.21.2" />
<PackageVersion Include="Casbin.NET" Version="2.21.2" />Directory.Packages.props
<PackageReference Include="Casbin.NET" />Project file
paket add Casbin.NET --version 2.21.2
#r "nuget: Casbin.NET, 2.21.2"
#:package Casbin.NET@2.21.2
#addin nuget:?package=Casbin.NET&version=2.21.2Install as a Cake Addin
#tool nuget:?package=Casbin.NET&version=2.21.2Install as a Cake Tool
👁 Build Status
👁 Coverage Status
👁 Nuget
👁 Release
👁 Nuget
👁 Discord
News: still worry about how to write the correct Casbin policy? Casbin online editor is coming to help! Try it at: http://casbin.org/editor/
Casbin.NET is a powerful and efficient open-source access control library for .NET (C#) 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 | Casbin4D | Casbin-RS |
| production-ready | production-ready | experimental | production-ready |
write-article, read-log. It doesn't control the access to a specific article or log.resource.Owner can be used to get the attribute for a resource./res/*, /res/:id and HTTP methods like GET, POST, PUT, DELETE.In Casbin, an access control model is abstracted into a CONF file based on the PERM metamodel (Policy, Effect, Request, Matchers). So switching or upgrading the authorization mechanism for a project is just as simple as modifying a configuration. You can customize your own access control model by combining the available models. For example, you can get RBAC roles and ABAC attributes together inside one model and share one set of policy rules.
The most basic and simplest model in Casbin is ACL. ACL's model CONF is:
# Request definition
[request_definition]
r = sub, obj, act
# Policy definition
[policy_definition]
p = sub, obj, act
# Policy effect
[policy_effect]
e = some(where (p.eft == allow))
# Matchers
[matchers]
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
An example policy for ACL model is like:
p, alice, data1, read
p, bob, data2, write
It means:
We also support multi-line mode by appending '\' in the end:
# Matchers
[matchers]
m = r.sub == p.sub && r.obj == p.obj \
&& r.act == p.act
Further more, if you are using ABAC, you can try operator in like following in Casbin golang edition (jCasbin and Node-Casbin are not supported yet):
# Matchers
[matchers]
m = r.obj == p.obj && r.act == p.act || r.obj in ('data2', 'data3')
But you SHOULD make sure that the length of the array is MORE than 1, otherwise there will cause it to panic.
For more operators, you may take a look at govaluate
What Casbin does:
{subject, object, action} form or a customized form as you defined, both allow and deny authorizations are supported.root or administrator. A superuser can do anything without explict permissions.keyMatch can map a resource key /foo/bar to the pattern /foo*.What Casbin does NOT do:
username and password when a user logs in)dotnet add package Casbin.NET
https://casbin.org/docs/overview
You can also use the online editor (http://casbin.org/editor/) to write your Casbin model and policy in your web browser. It provides functionality such as syntax highlighting and code completion, just like an IDE for a programming language.
https://casbin.org/docs/tutorials
New a Casbin enforcer with a model file and a policy file:
var e = new Enforcer("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.
Add an enforcement hook into your code right before the access happens:
var sub = "alice" // the user that wants to access a resource.
var obj = "data1" // the resource that is going to be accessed.
var act = "read" // the operation that the user performs on the resource.
if (e.Enforce(sub, obj, act)) {
// permit alice to read data1
} else {
// deny the request, show an error
}
Besides the static policy file, Casbin also provides API for permission management at run-time. For example, You can get all the roles assigned to a user as below:
var roles = e.GetRolesForUser("alice")
See Policy management APIs for more usage.
Casbin.UnitTest project for more usage.Casbin provides two sets of APIs to manage permissions:
We also provide a web-based UI for model management and policy management:
https://casbin.org/docs/adapters
https://casbin.org/docs/watchers
https://casbin.org/docs/role-managers
https://casbin.org/docs/benchmark
| Model | Model file | Policy file |
|---|---|---|
| ACL | basic_model.conf | basic_policy.csv |
| ACL with superuser | basic_model_with_root.conf | basic_policy.csv |
| ACL without users | basic_model_without_users.conf | basic_policy_without_users.csv |
| ACL without resources | basic_model_without_resources.conf | basic_policy_without_resources.csv |
| RBAC | rbac_model.conf | rbac_policy.csv |
| RBAC with resource roles | rbac_model_with_resource_roles.conf | rbac_policy_with_resource_roles.csv |
| RBAC with domains/tenants | rbac_model_with_domains.conf | rbac_policy_with_domains.csv |
| ABAC | abac_model.conf | N/A |
| RESTful | keymatch_model.conf | keymatch_policy.csv |
| Deny-override | rbac_model_with_deny.conf | rbac_policy_with_deny.csv |
| Priority | priority_model.conf | priority_policy.csv |
Authz middlewares for web frameworks: https://casbin.org/docs/middlewares
https://casbin.org/docs/adopters
This project exists thanks to all the people who contribute. <p><a href="https://github.com/apache/casbin-Casbin.NET/graphs/contributors"><img src="https://opencollective.com/casbinnet/contributors.svg?width=890&button=false"></a></p>
This project is licensed under the .
If you have any issues or feature requests, please contact us. PR is welcomed.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 is compatible. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 is compatible. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net452 net452 is compatible. net46 net46 was computed. net461 net461 is compatible. net462 net462 is compatible. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Casbin.NET:
| Package | Downloads |
|---|---|
|
Casbin.NET.Adapter.EFCore
Package Description |
|
|
Casbin.AspNetCore.Abstractions
Package Description |
|
|
Casbin.NET.Watcher.Redis
Redis watcher for Casbin.NET |
|
|
Casbin.Watcher.Redis
Redis watcher for Casbin.NET |
|
|
Looplex.Foundation
Looplex package that contains foundation/core code for projects with Hexagonal/Micro-Kernel architectures. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.21.2 | 121 | 6/16/2026 |
| 2.21.1 | 42 | 6/16/2026 |
| 2.19.2 | 57,553 | 1/1/2026 |
| 2.19.1 | 66,992 | 11/7/2025 |
| 2.19.0 | 753 | 11/1/2025 |
| 2.18.0 | 170 | 11/1/2025 |
| 2.17.0 | 198 | 10/31/2025 |
| 2.16.0 | 7,278 | 9/27/2025 |
| 2.15.0 | 1,292 | 9/24/2025 |
| 2.14.0 | 340 | 9/22/2025 |
| 2.13.0 | 2,398 | 9/2/2025 |
| 2.12.0 | 259,628 | 10/29/2024 |
| 2.11.0 | 8,724 | 10/29/2024 |
| 2.10.0 | 33,890 | 9/3/2024 |
| 2.9.1 | 36,256 | 8/11/2024 |
| 2.9.0 | 23,078 | 6/18/2024 |
| 2.8.0 | 11,797 | 6/6/2024 |
| 2.7.1 | 3,417 | 5/30/2024 |
| 2.7.0 | 397,926 | 4/27/2024 |
| 2.6.0 | 1,161 | 4/22/2024 |