1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-07 11:40:31 -05:00

PM-20532 - Add first draft of ClaimsPrincipal extension GetSendId for getting send id in send claim protected controller methods.

This commit is contained in:
Jared Snider 2025-05-30 17:32:13 -04:00
parent a08441c896
commit 1b65b8a2c9
No known key found for this signature in database
GPG Key ID: A149DDD612516286

View File

@ -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;
}
}