IAuthorizationRequirement is a blank ASP.NET Core marker interface for classes that represent authorization requirements. Requirement classes are usually lightweight POCOs: they identify what a policy must satisfy, while authorization handlers contain the decision logic. section 24.4.2
A requirement can be modeled in two common ways:
- Create requirement instances manually when adding them to a policy; do not use dependency injection in the requirement itself. Put injected dependencies in handlers instead. section 24.4.2
Combining requirements in a policy
builder.Services.AddAuthorization(options => { options.AddPolicy("CanAccessLounge", policyBuilder => policyBuilder.AddRequirements( new MinimumAgeRequirement(18), new AllowedInLoungeRequirement())); }); Each requirement represents one condition that must be satisfied for the policy to succeed. Handlers can call context.Succeed(requirement) when their condition is met or context.Fail() when access must be denied.
