Enigmatry.Entry.AspNetCore.Authorization
9.5.0
dotnet add package Enigmatry.Entry.AspNetCore.Authorization --version 9.5.0
NuGet\Install-Package Enigmatry.Entry.AspNetCore.Authorization -Version 9.5.0
<PackageReference Include="Enigmatry.Entry.AspNetCore.Authorization" Version="9.5.0" />
<PackageVersion Include="Enigmatry.Entry.AspNetCore.Authorization" Version="9.5.0" />
<PackageReference Include="Enigmatry.Entry.AspNetCore.Authorization" />
paket add Enigmatry.Entry.AspNetCore.Authorization --version 9.5.0
#r "nuget: Enigmatry.Entry.AspNetCore.Authorization, 9.5.0"
#:package Enigmatry.Entry.AspNetCore.Authorization@9.5.0
#addin nuget:?package=Enigmatry.Entry.AspNetCore.Authorization&version=9.5.0
#tool nuget:?package=Enigmatry.Entry.AspNetCore.Authorization&version=9.5.0
Authorization Building Block
Building Block with startup extensions for enabling permission-based authorization
Registration
You can use the AppAddAuthorization extension method on IServiceCollection.
This will register RequirementHandlers for permission-based authorization for the specified permission type (TPermission):
public void ConfigureServices(IServiceCollection services)
{
...
services.AppAddAuthorization<TPermission>();
}
Permission type
Underneath the covers, policy based authentication is used through a custom IAuthorizationPolicyProvider implementation and permissions are encoded to a policy name.
As a result, the permission type must be capable of converting to and from a string.
Types such as 'String', 'Enum', and 'int' are automatically supported. If you want to use a custom permission type, you must implement [System.ComponentModel.TypeConverter].(https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.typeconverter).
For the rest of the examples in this document, let's use an enum as the permission type:
public enum PermissionId
{
Read,
Write
}
Securing API methods
To secure a method on a controller, you can now use UserHasPermission with list of requred permissions:
[HttpGet("UserWithPermissionIsAllowed")]
[UserHasPermission<PermissionId>(PermissionId.Read, PermissionId.Write)]
public IEnumerable<WeatherForecast> UserWithPermissionIsAllowed() => Array.Empty<WeatherForecast>();
Implementing authorization checks
Because the actual check if the current user has the right permissions can be application-specific, this building block only provides an interface IAuthorizationProvider, with no default implementation:
public interface IAuthorizationProvider<in TPermission> where TPermission : notnull
{
public bool AuthorizePermissions(IEnumerable<TPermission> permissions);
}
Applications using this building block need to register their own implementation:
services.AddScoped<IAuthorizationProvider<PermissionId>, SampleAuthorizationProvider>();
public class SampleAuthorizationProvider : IAuthorizationProvider<PermissionId>
{
public bool AuthorizePermissions(IEnumerable<PermissionId> permissions) =>
// Let's assume the current user only has the 'Read' permission
permissions.Any(p => p == PermissionId.Read);
}
| 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
- AutoMapper (= 14.0.0)
- Ben.Demystifier (>= 0.4.1)
- Enigmatry.Entry.AspNetCore (>= 9.5.0)
- FluentValidation (>= 12.1.1)
- JetBrains.Annotations (>= 2025.2.4)
- MediatR (= 12.4.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.12)
- Microsoft.Extensions.Options (>= 9.0.12)
- Serilog (>= 4.3.0)
- System.ComponentModel.Annotations (>= 5.0.0)
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 |
|---|---|---|
| 9.5.0 | 394 | 1/26/2026 |
| 9.4.0 | 372 | 12/22/2025 |
| 9.3.1-preview.3 | 252 | 12/18/2025 |
| 9.3.1-preview.1 | 162 | 11/25/2025 |
| 9.3.0 | 756 | 11/10/2025 |
| 9.2.0 | 792 | 9/24/2025 |
| 9.1.1-preview.5 | 222 | 8/8/2025 |
| 9.1.1-preview.4 | 137 | 6/27/2025 |
| 9.1.1-preview.3 | 162 | 6/4/2025 |
| 9.1.0 | 394 | 6/3/2025 |
| 9.0.1-preview.8 | 169 | 5/26/2025 |
| 9.0.1-preview.7 | 244 | 5/13/2025 |
| 9.0.1-preview.6 | 398 | 5/9/2025 |
| 9.0.1-preview.5 | 181 | 5/7/2025 |
| 9.0.1-preview.4 | 172 | 4/30/2025 |
| 8.3.1-preview.1 | 140 | 12/24/2025 |
| 8.3.0 | 469 | 12/23/2025 |
| 8.2.0 | 390 | 9/24/2025 |
| 8.1.1-preview.3 | 171 | 5/7/2025 |
| 8.1.1-preview.1 | 175 | 4/1/2025 |