Security.RBAC
1.0.0
dotnet add package Security.RBAC --version 1.0.0
NuGet\Install-Package Security.RBAC -Version 1.0.0
<PackageReference Include="Security.RBAC" Version="1.0.0" />
<PackageVersion Include="Security.RBAC" Version="1.0.0" />
<PackageReference Include="Security.RBAC" />
paket add Security.RBAC --version 1.0.0
#r "nuget: Security.RBAC, 1.0.0"
#:package Security.RBAC@1.0.0
#addin nuget:?package=Security.RBAC&version=1.0.0
#tool nuget:?package=Security.RBAC&version=1.0.0
Security.RBAC NuGet Package
Reusable RBAC (Role-Based Access Control) package for ASP.NET Core with permission-based authorization.
Features
- Attribute-based permission checks
[HasPermissions]. - Policy provider and handler wired into ASP.NET Core's authorization system.
- Easy integration with ASP.NET Identity.
Installation
To use Security.RBAC in your ASP.NET Core project, you can install the package via NuGet Package Manager or by using the .NET CLI:
Using NuGet Package Manager
Install-Package Security.RBAC
Using .NET CLI
dotnet add package Security.RBAC
Using PackageReference
Add the following line to your .csproj file:
<PackageReference Include="Security.RBAC" Version="1.0.0" />
Getting Started
- Add the necessary services in your
Startup.csorProgram.csfile:
services.AddRbacAuthorization();
- Use the
[HasPermissions]attribute on your controllers or actions to enforce permission checks:
public class UsersController : Controller
{
[HasPermissions("Users.Create", "Users.Update")]
public IActionResult Upsert() => Ok();
}
Using Permission Store and Manager (Optional)
If you need to manage permissions in a table:
- Register a custom or default permission type in
Program.csorStartup.cs:
services.AddRbac(typeof(MyCustomPermission)) // or simply use IdentityPermission
.AddRbacPermissionStore<MyPermissionStore>()
.AddRbacPermissionValidator<MyPermissionValidator>()
.AddRbacPermissionManager<MyPermissionManager>();
Or use the default built-in setup:
services.AddRbac().AddDefaultRbacPermission();
- Implement the following interfaces based on your permission entity:
IPermissionStore<TPermission>IPermissionValidator<TPermission>PermissionManager<TPermission>
Example:
public class MyPermissionStore : IPermissionStore<IdentityPermission>
{
// Implement your logic to fetch permissions from the database
}
Example Permission Entity:
You can use the built-in IdentityPermission or define your own:
public class MyCustomPermission : IdentityPermission
{
// Add additional fields if needed
}
Integration with ASP.NET Identity
Security.RBAC is designed to work seamlessly with ASP.NET Identity. You can store permissions in your Identity database or a separate table and fetch them dynamically.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Microsoft.AspNetCore.Authorization (>= 9.0.4)
- Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|