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<T>.
#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
