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:
parent
a08441c896
commit
1b65b8a2c9
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user