liveBook · Manning

Succeed

As explained in ASP.NET Core in Action, 3e

Succeed is an authorization-handler operation that marks a specified requirement as satisfied.

Succeed is an authorization-handler operation that marks a specified requirement as satisfied. A handler calls context.Succeed(requirement) when the current user meets its condition. section 24.4.2

Handlers can remain silent when they cannot satisfy a requirement. This lets another associated handler succeed; only one handler must succeed, while every policy requirement must be satisfied. section 24.4.2 section 24.7

Allowing a frequent flyer into a lounge

A FrequentFlyerHandler checks whether the user has a FrequentFlyerClass claim with the value Gold. If the claim exists, it calls context.Succeed(requirement), satisfying AllowedInLoungeRequirement; otherwise, it returns without changing the context. section 24.4.2

Listing 24.8 FrequentFlyerHandler for AllowedInLoungeRequirement
public class FrequentFlyerHandler :
    AuthorizationHandler<AllowedInLoungeRequirement>              #1
{
    protected override Task HandleRequirementAsync(               #2
        AuthorizationHandlerContext context,                      #3
        AllowedInLoungeRequirement requirement)                   #4
    {
        if(context.User.HasClaim("FrequentFlyerClass", "Gold"))   #5
        {
            context.Succeed(requirement);                         #6
        }
        return Task.CompletedTask;                                #7
    }
}
#1 The handler implements AuthorizationHandler&lt;T&gt;.
#2 You must override the abstract HandleRequirementAsync method.
#3 The context contains details such as the ClaimsPrincipal user object.
#4 The requirement instance to handle
#5 Checks whether the user has the Frequent-FlyerClass claim with the Gold value
#6 If the user had the necessary claim, marks the requirement as satisfied by calling Succeed
#7 If the requirement wasn’t satisfied, does nothing

Use the handler listing to see the requirement, authorization context, claim check, Succeed call, and completed task together. section 24.4.2

Succeed does not override an explicit failure. If another handler calls context.Fail(), authorization fails even when a different handler previously called Succeed. section 24.7

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains the call, silent-handler behavior, multiple-handler evaluation, and explicit failure precedence without descending into framework internals.
Examples
Uses an airport-lounge policy where Gold or employee claims can satisfy AllowedInLoungeRequirement.
What it assumes
Assumes authorization policies, requirements, handlers, and claims, while showing the success call within a handler.
What you can do after
Apply it via ASP.NET authorization handlers to mark requirements successful during policy evaluation.
How it connects
Connects authorization handlers with requirements, authorization policies, claims, and context.Fail.

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.