1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-11-25 07:42:58 +01:00
Minecraft-Phantom-Panel/Web/Phantom.Web.Services/Authorization/PermissionBasedPolicyHandler.cs

18 lines
624 B
C#

using Microsoft.AspNetCore.Authorization;
using Phantom.Web.Services.Authentication;
namespace Phantom.Web.Services.Authorization;
sealed class PermissionBasedPolicyHandler : AuthorizationHandler<PermissionBasedPolicyRequirement> {
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionBasedPolicyRequirement requirement) {
if (context.User.CheckPermission(requirement.Permission)) {
context.Succeed(requirement);
}
else {
context.Fail(new AuthorizationFailureReason(this, "Missing permission: " + requirement.Permission.Id));
}
return Task.CompletedTask;
}
}