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:
@@ -96,6 +96,21 @@ public static class ReceiverClaimExtensions
|
|||||||
throw new InvalidOperationException($"Claim '{EnvelopeClaimNames.ReceiverId}' is not a valid integer.");
|
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>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user