This project demonstrates how to implement custom authorization policies in ASP.NET Core using the IAuthorizationPolicyProvider
.
The goal is to provide a solution for scenarios where policies cannot be registered statically or when policies based on dynamic parameters are required.
-
Custom Policy Provider: Implements a custom
IAuthorizationPolicyProvider
that dynamically generates authorization policies based on specific requirements. -
Custom Authorization Attribute: Defines an authorization attribute that accepts parameters, enabling the application of policies based on dynamic conditions directly on controllers or actions.
-
Custom Requirement Handlers: Includes handlers that evaluate the policy requirements at runtime, determining whether a user meets the defined criteria.
-
Controllers/: Contains MVC controllers that demonstrate the application of custom authorization policies.
-
Data/: Includes classes related to data access and Entity Framework Core configuration.
-
Identity/: Houses implementations related to identity and authorization, including the custom policy provider and requirement handlers.
-
Migrations/: Contains Entity Framework Core migrations to configure the database schema.
- ASP.NET Core 6.0 or later.
- Entity Framework Core for data access.
-
Clone the repository:
git clone https://github.com/JohnSalazar/AspNetCoreIdentityAuthorizationCustom.git
-
Navigate to the project directory:
cd AspNetCoreIdentityAuthorizationCustom
-
Restore dependencies:
dotnet restore
-
Update the database:
dotnet ef database update
-
Run the application:
dotnet run
This project serves as a practical guide for developers looking to implement more flexible and dynamic authorization solutions in their ASP.NET Core applications.
This project was developed by JohnSalazar under the MIT license.