diff --git a/EnvelopeGenerator.API/Controllers/Interfaces/IAuthController.cs b/EnvelopeGenerator.API/Controllers/Interfaces/IAuthController.cs new file mode 100644 index 00000000..cf31d972 --- /dev/null +++ b/EnvelopeGenerator.API/Controllers/Interfaces/IAuthController.cs @@ -0,0 +1,38 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; + +namespace EnvelopeGenerator.API.Controllers.Interfaces; + +/// +/// +/// +public interface IAuthController +{ + /// + /// + /// + IAuthorizationService AuthService { get; } + + /// + /// + /// + ClaimsPrincipal User { get; } +} + +/// +/// +/// +public static class AuthControllerExtensions +{ + /// + /// + /// + /// + /// + /// + public static async Task IsUserInPolicyAsync(this IAuthController controller, string policyName) + { + var result = await controller.AuthService.AuthorizeAsync(controller.User, policyName); + return result.Succeeded; + } +} \ No newline at end of file