mirror of
https://github.com/bitwarden/server
synced 2025-12-27 05:33:17 +00:00
[PM-22739] Add ClaimsPrincipal Extension
feat: add ClaimsPrincipal Extension test: add tests
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using System.Security.Claims;
|
||||
using Bit.Core.Identity;
|
||||
|
||||
namespace Bit.Core.Auth.UserFeatures.SendAccess;
|
||||
|
||||
public static class SendAccessClaimsPrincipalExtensions
|
||||
{
|
||||
public static Guid GetSendId(this ClaimsPrincipal user)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(user);
|
||||
|
||||
var sendIdClaim = user.FindFirst(Claims.SendId)
|
||||
?? 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user