Enigmatry.Entry.AspNetCore.Authorization
9.1.1-preview.4
dotnet add package Enigmatry.Entry.AspNetCore.Authorization --version 9.1.1-preview.4
NuGet\Install-Package Enigmatry.Entry.AspNetCore.Authorization -Version 9.1.1-preview.4
<PackageReference Include="Enigmatry.Entry.AspNetCore.Authorization" Version="9.1.1-preview.4" />
<PackageVersion Include="Enigmatry.Entry.AspNetCore.Authorization" Version="9.1.1-preview.4" />
<PackageReference Include="Enigmatry.Entry.AspNetCore.Authorization" />
paket add Enigmatry.Entry.AspNetCore.Authorization --version 9.1.1-preview.4
#r "nuget: Enigmatry.Entry.AspNetCore.Authorization, 9.1.1-preview.4"
#addin nuget:?package=Enigmatry.Entry.AspNetCore.Authorization&version=9.1.1-preview.4&prerelease
#tool nuget:?package=Enigmatry.Entry.AspNetCore.Authorization&version=9.1.1-preview.4&prerelease
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
- Enigmatry.Entry.AspNetCore (>= 9.1.1-preview.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 |
---|---|---|
9.1.1-preview.4 | 58 | 6/27/2025 |
9.1.1-preview.3 | 110 | 6/4/2025 |
9.1.0 | 134 | 6/3/2025 |
9.0.1-preview.8 | 116 | 5/26/2025 |
9.0.1-preview.7 | 200 | 5/13/2025 |
9.0.1-preview.6 | 162 | 5/9/2025 |
9.0.1-preview.5 | 140 | 5/7/2025 |
9.0.1-preview.4 | 118 | 4/30/2025 |
9.0.1-preview.2 | 122 | 4/1/2025 |
9.0.0 | 504 | 2/26/2025 |
8.1.1-preview.3 | 119 | 5/7/2025 |
8.1.1-preview.1 | 122 | 4/1/2025 |
8.1.0 | 419 | 2/19/2025 |
8.0.1-preview.4 | 68 | 2/7/2025 |
8.0.1-preview.2 | 50 | 1/15/2025 |
8.0.0 | 1,018 | 11/27/2024 |
3.4.6-preview.10 | 64 | 11/27/2024 |
3.4.3 | 439 | 10/22/2024 |
3.4.2 | 494 | 10/11/2024 |
3.4.1 | 137 | 10/9/2024 |
3.4.0 | 119 | 10/9/2024 |
3.3.2 | 250 | 8/28/2024 |
3.3.2-preview.7 | 80 | 8/27/2024 |
3.3.1 | 313 | 7/16/2024 |
3.3.1-preview.4 | 69 | 7/12/2024 |
3.3.0 | 1,116 | 6/20/2024 |
3.2.1-preview.4 | 68 | 6/17/2024 |
3.2.1-preview.1 | 69 | 5/23/2024 |
3.2.0 | 827 | 4/3/2024 |
3.1.1-preview.1 | 77 | 3/13/2024 |
3.1.0 | 341 | 3/8/2024 |
3.1.0-preview.2 | 135 | 2/19/2024 |
3.0.1-preview.2 | 1,132 | 2/9/2024 |
3.0.1-preview.1 | 85 | 1/24/2024 |
3.0.0 | 366 | 1/15/2024 |
3.0.0-preview.14 | 107 | 1/9/2024 |
3.0.0-preview.12 | 74 | 1/9/2024 |
3.0.0-preview.5 | 70 | 1/10/2024 |
3.0.0-preview.2 | 132 | 12/28/2023 |
3.0.0-preview | 169 | 12/20/2023 |
2.1.0 | 185 | 12/28/2023 |
2.0.1-preview.3 | 118 | 12/1/2023 |
2.0.1-preview.2 | 92 | 11/29/2023 |
2.0.1-preview.1 | 87 | 11/28/2023 |
2.0.0 | 271 | 11/8/2023 |
2.0.0-preview.3 | 462 | 10/27/2023 |
2.0.0-preview.2 | 84 | 10/27/2023 |
2.0.0-preview.1 | 84 | 10/27/2023 |
2.0.0-preview | 139 | 10/27/2023 |
1.1.500 | 152 | 10/27/2023 |
1.1.495 | 874 | 9/24/2023 |
1.1.486 | 470 | 9/13/2023 |
1.1.484 | 162 | 9/7/2023 |
1.1.482 | 160 | 9/6/2023 |
1.1.480 | 189 | 8/24/2023 |
1.1.477 | 509 | 8/2/2023 |
1.1.464 | 168 | 7/5/2023 |
1.1.447 | 222 | 5/26/2023 |