using Microsoft.AspNetCore.Mvc; using System.Security.Claims; namespace EnvelopeGenerator.Web.Controllers { public static class ControllerBaseExtensions { public static (string EnvelopeUuid, string ReceiverSignature)? GetAuthenticatedEnvelopeDetails(this ControllerBase controller) { if(controller?.User?.Identity?.IsAuthenticated ?? false) { var envelopeUuid = controller.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var receiverSignature = controller.User.FindFirst(ClaimTypes.Hash)?.Value; if (!string.IsNullOrEmpty(envelopeUuid) && !string.IsNullOrEmpty(receiverSignature)) return (EnvelopeUuid: envelopeUuid, ReceiverSignature: receiverSignature); } return null; } public static string? GetAuthenticatedEnvelopeUuid(this ControllerBase controller) { if (controller?.User?.Identity?.IsAuthenticated ?? false) { var envelopeUuid = controller.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (!string.IsNullOrEmpty(envelopeUuid)) return envelopeUuid; } return null; } public static string? GetAuthenticatedReceiverSignature(this ControllerBase controller) { if (controller?.User?.Identity?.IsAuthenticated ?? false) { var receiverSignature = controller.User.FindFirst(ClaimTypes.Hash)?.Value; if (!string.IsNullOrEmpty(receiverSignature)) return receiverSignature; } return null; } } }