feat: add SenderId() extension to ClaimsPrincipal

Extracts the authenticated sender's integer ID from the 'sub' /
NameIdentifier claim. Mirrors the existing ReceiverId() helper and is
required by GetDocumentOfSenderAsync.
This commit is contained in:
2026-09-23 15:32:36 +02:00
parent 86758bb127
commit 999fac7dac

View File

@@ -96,6 +96,21 @@ public static class ReceiverClaimExtensions
throw new InvalidOperationException($"Claim '{EnvelopeClaimNames.ReceiverId}' is not a valid integer.");
}
/// <summary>
/// Gets the authenticated sender identifier from the 'sub' claim.
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public static int SenderId(this ClaimsPrincipal user)
{
var senderIdStr = user.GetRequiredClaimValue(JwtRegisteredClaimNames.Sub, ClaimTypes.NameIdentifier);
if (int.TryParse(senderIdStr, out var senderId))
return senderId;
else
throw new InvalidOperationException($"Claim '{JwtRegisteredClaimNames.Sub}' is not a valid integer.");
}
/// <summary>
///
/// </summary>