From e52972ee9b78ccfd5a5684a672cd5818083485b8 Mon Sep 17 00:00:00 2001 From: TekH Date: Sat, 6 Jun 2026 18:06:20 +0200 Subject: [PATCH] Add ReceiverId claim handling to ReceiverClaimExtensions Updated ReceiverClaimExtensions to include a new array, `ReceiverIdClaimTypes`, for receiver ID claim types. Added `GetReceiverIdOfReceiver` method to retrieve and validate receiver ID claims. Modified the exception message in `GetEnvelopeIdOfReceiver` to use a string literal for clarity. --- .../Extensions/ReceiverClaimExtensions.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/EnvelopeGenerator.API/Extensions/ReceiverClaimExtensions.cs b/EnvelopeGenerator.API/Extensions/ReceiverClaimExtensions.cs index 05f3c878..b3760d59 100644 --- a/EnvelopeGenerator.API/Extensions/ReceiverClaimExtensions.cs +++ b/EnvelopeGenerator.API/Extensions/ReceiverClaimExtensions.cs @@ -12,6 +12,7 @@ namespace EnvelopeGenerator.API.Extensions; public static class ReceiverClaimExtensions { private static readonly string[] EnvelopeIdClaimTypes = [EnvelopeClaimTypes.Id, "envelope_id", "EnvelopeId"]; + private static readonly string[] ReceiverIdClaimTypes = ["receiver_id", "ReceiverId"]; private static readonly string[] EnvelopeUuidClaimTypes = [ClaimTypes.NameIdentifier, "envelope_uuid", "EnvelopeUuid"]; private static readonly string[] ReceiverSignatureClaimTypes = [ClaimTypes.Hash, "receiver_sig", "ReceiverSignature"]; @@ -81,12 +82,29 @@ public static class ReceiverClaimExtensions var envIdStr = user.GetRequiredClaimOfReceiver(EnvelopeIdClaimTypes); if (!int.TryParse(envIdStr, out var envId)) { - throw new InvalidOperationException($"Claim '{EnvelopeClaimTypes.Id}' is not a valid integer."); + throw new InvalidOperationException($"Claim '{"envelope_id"}' is not a valid integer."); } return envId; } + /// + /// + /// + /// + /// + /// + public static int GetReceiverIdOfReceiver(this ClaimsPrincipal user) + { + var rcvIdStr = user.GetRequiredClaimOfReceiver(ReceiverIdClaimTypes); + if (!int.TryParse(rcvIdStr, out var rcvId)) + { + throw new InvalidOperationException($"Claim '{"receiver_id"}' is not a valid integer."); + } + + return rcvId; + } + /// /// Signs in an envelope receiver using cookie authentication and attaches envelope claims. ///