From ef7c9c2b9797f0e671dbade3aaa9371fe159cdc4 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 6 Feb 2026 13:39:14 +0100 Subject: [PATCH] Add IAuthController interface and policy check extension Introduced IAuthController with AuthService and User properties to standardize authentication handling. Added AuthorizationControllerExtensions with IsUserInPolicyAsync to simplify policy-based authorization checks. Included necessary using directives. --- .../Controllers/Interfaces/IAuthController.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 EnvelopeGenerator.API/Controllers/Interfaces/IAuthController.cs 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