diff --git a/src/Core/Auth/UserFeatures/SendAccess/SendAccessClaimsPrincipalExtensions.cs b/src/Core/Auth/UserFeatures/SendAccess/SendAccessClaimsPrincipalExtensions.cs new file mode 100644 index 0000000000..0bf0777914 --- /dev/null +++ b/src/Core/Auth/UserFeatures/SendAccess/SendAccessClaimsPrincipalExtensions.cs @@ -0,0 +1,23 @@ +using System.Security.Claims; +using Bit.Core.Identity; + +namespace Bit.Core.Auth.UserFeatures.SendAccess; + +// TODO: test this with test file in Tests/Core/Auth/UserFeatures/SendAccess/SendAccessClaimsPrincipalExtensionsTests.cs +public static class SendAccessClaimsPrincipalExtensions +{ + public static Guid GetSendId(this ClaimsPrincipal user) + { + ArgumentNullException.ThrowIfNull(user); + + var sendIdClaim = user.FindFirst(Claims.SendId); + if (sendIdClaim == null) throw new InvalidOperationException("Send ID claim not found."); + + if (!Guid.TryParse(sendIdClaim.Value, out var sendGuid)) + { + throw new InvalidOperationException("Invalid Send ID claim value."); + } + + return sendGuid; + } +}