authorization-policy-generator
/authorization-policy-generator
Design ASP.NET Core authorization — policy-based, role-based, and claims/requirement-based with custom authorization handlers and resource-based checks. Use this skill whenever the user wants authorization policies, role/claim checks, custom AuthorizationHandler, resource-based authorization, permission checks, or asks "how do I authorize this / policy vs role / restrict this endpoint to X". Always use this skill for authorization requests; it generates policies, handlers, and endpoint wiring.
- Author
- stefanthecode ↗
- Repository
- dotnet-ai-toolkit ↗
- Licence
- MIT
- Last repository change
- 09.08.2026
Assessment and security
- Files in this package
- 2
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 09.08.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Design ASP.NET Core authorization — policy-based, role-based, and claims/requirement-based with custom authorization handlers and resource-based checks. Use this skill whenever the user wants authorization policies, role/claim checks, custom AuthorizationHandler, resource-based authorization, permission checks, or asks "how do I authorize this / policy vs role / restrict this endpoint to X". Always use this skill for authorization requests; it generates policies, handlers, and endpoint wiring.
Original author description
Design ASP.NET Core authorization — policy-based, role-based, and claims/requirement-based with custom authorization handlers and resource-based checks. Use this skill whenever the user wants authorization policies, role/claim checks, custom AuthorizationHandler, resource-based authorization, permission checks, or asks "how do I authorize this / policy vs role / restrict this endpoint to X". Always use this skill for authorization requests; it generates policies, handlers, and endpoint wiring.
How it works
- Input — point it at your project
- Named policies (not role strings everywhere)
- Custom requirement + handler (real business rules)
- Resource-based (can THIS user act on THIS object)
- Wiring endpoints
- Principles
- How to use it & best prompts
SKILL.md preview
---
name: authorization-policy-generator
description: Design ASP.NET Core authorization — policy-based, role-based, and claims/requirement-based with custom authorization handlers and resource-based checks. Use this skill whenever the user wants authorization policies, role/claim checks, custom AuthorizationHandler, resource-based authorization, permission checks, or asks "how do I authorize this / policy vs role / restrict this endpoint to X". Always use this skill for authorization requests; it generates policies, handlers, and endpoint wiring.
category: Security
version: 1.0.0
---
# Authorization Policy Generator
Design ASP.NET Core authorization the right way: named policies over scattered role strings, custom requirements/handlers for real rules, and resource-based checks for "can this user act on this object".
## Input — point it at your project
Works on a target: a **project** or **GitHub URL**. Inspect current setup: `grep -rn "AddAuthorization\|RequireRole\|RequireClaim\|\[Authorize\|RequireAuthorization\|IAuthorizationHandler" --include=*.cs <target>`.
## Named policies (not role strings everywhere)
```csharp
builder.Services.AddAuthorizationBuilder()
.AddPolicy("CanManageOrders", p => p.RequireClaim("permission", "orders:manage"))
.AddPolicy("AdminOnly", p => p.RequireRole("Admin"))
.AddPolicy("Over18", p => p.AddRequirements(new MinimumAgeRequirement(18)));
```
## Custom requirement + handler (real business rules)
```csharp
public record MinimumAgeRequirement(int Age) : IAuthorizationRequirement;
public class MinimumAgeHandler : AuthorizationHandler<MinimumAgeRequirement>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext ctx, MinimumAgeRequirement req)
{
var dob = ctx.User.FindFirst("dob")?.Value;
if (DateTime.TryParse(dob, out var d) && d.AddYears(req.Age) <= DateTime.Today)
ctx.Succeed(req);
return Task.CompletedTask;
}
}
builder.Services.AddSingleton<IAuthorizationHandler, MinimumAgeHandler>();
```
## Resource-based (can THIS user act on THIS object)
```csharp
var auth = await _authService.AuthorizeAsync(User, order, "OrderOwnerPolicy");
if (!auth.Succeeded) return Results.Forbid();
```
This is how you stop IDOR — ownership checked against the actual resource, not just a role.
## Wiring endpoints
```csharp
app.MapPost("/orders", ...).RequireAuthorization("CanManageOrders");
group.RequireAuthorization("AdminOnly");
// Consider a FallbackPolicy so endpoints are authenticated by default.
```
## Principles
- **Policies over inline role strings** — one named policy, reused, easy to change.
- **Requirements/handlers for business rules**, not giant `if (User.IsInRole(...))` blocks.
- **Resource-based authorization** prevents IDOR — check ownership, not just role.
- Consider a **fallback policy** so new endpoints aren't accidentally anonymous.
## How to use it & best prompts
"Design authorization policies for my API", "restrict this endpoint to managers", "add a custom authorization rule", "stop users from accessing others' records" (resource-based). Pairs with `jwt-auth-setup` and the `aspnetcore-security-auditor` agent.
Files in this package (2)
- SKILL.md 3 KB
- USAGE.md 1 KB
Versions
The database has no other skills named authorization-policy-generator.
Database snapshot: 13.11.2026 · package version 5e78f84a22c1 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Similar skills
- 100authorize-resources
Grant access to a specific entity instance ("edit this document") rather than a global permission — using ABP resource permissions or a standard ASP.NET Core AuthorizationHandler with a resource. USE FOR: per-owner or per-instance access (this project, this document),… - 100authentication
Authentication and authorization for ASP.NET Core. Covers JWT bearer tokens, OpenID Connect, ASP.NET Identity, authorization policies, role and claim-based authorization, and API key authentication. Load this skill when implementing login, protecting endpoints, designing… - 100jwt-auth-setup
Set up JWT authentication and authorization in ASP.NET Core. Use this skill whenever the user wants to add login/auth, issue or validate JWT tokens, set up bearer authentication, refresh tokens, role/policy-based authorization, claims, or asks "how do I secure my API / add JWT… - 90dotnet-aspnetcore-identity-authz-review
Use this skill when reviewing how an ASP.NET Core application authenticates and authorizes requests — authentication schemes, JWT TokenValidationParameters, cookie and session security, policy-based authorization, authorization handlers, claims trust, role-versus-resource… - 100aspnet-identity
Guidance for ASP.NET Core Identity authentication and user management. USE FOR: user registration, login/logout flows, password management, two-factor authentication, role-based authorization, external login providers, account confirmation, token generation. DO NOT USE FOR:… - 100enforcer
Guidance for Casbin.NET authorization library (Enforcer). USE FOR: access control list (ACL) enforcement, role-based access control (RBAC), attribute-based access control (ABAC), policy management, multi-tenant authorization, API endpoint protection. DO NOT USE FOR:…