liveBook · Manning

Policy

As explained in Building Web APIs with ASP.NET Core

An authorization policy is a named set of requirements that determines whether an authenticated principal may perform an operation.

An authorization policy is a named set of requirements that determines whether an authenticated principal may perform an operation. Unlike role checks, policy requirements must be explicitly declared and registered in Program.cs, then selected through the Authorize attribute. section 9.4.7

Policies support claims-based checks such as requiring both the Moderator role and a mobile-phone claim. More complex requirements can use an assertion, such as checking whether a date-of-birth claim establishes a minimum age. section 9.4.7

builder.Services.AddAuthorization(options => 
{
    options.AddPolicy("ModeratorWithMobilePhone", policy =>
        policy
            .RequireClaim(ClaimTypes.Role, RoleNames.Moderator)#1
            .RequireClaim(ClaimTypes.MobilePhone));             #2
});

Register a named policy with RequireClaim, then apply it to an endpoint with the Authorize attribute; related listings demonstrate an assertion-based age policy. section 9.4.7

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Shows policy registration, endpoint application, claim combinations, and assertion logic, while deferring full implementation of the example.
Examples
Demonstrates ModeratorWithMobilePhone and MinAge18 policies using claims, roles, and assertion-based date checks.
What it assumes
Assumes authenticated users and claims, while contrasting policy checks with familiar role-based authorization.
What you can do after
Apply named policies through Program.cs registration and the Authorize attribute.
How it connects
Connects authorization policies with authentication, claims-based access control, role-based access control, claims, and JWT tokens.

Also explained in

Compare how 13 books explain policy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.