Add ReceiverId claim handling to ReceiverClaimExtensions
Updated ReceiverClaimExtensions to include a new array, `ReceiverIdClaimTypes`, for receiver ID claim types. Added `GetReceiverIdOfReceiver` method to retrieve and validate receiver ID claims. Modified the exception message in `GetEnvelopeIdOfReceiver` to use a string literal for clarity.
This commit is contained in:
@@ -12,6 +12,7 @@ namespace EnvelopeGenerator.API.Extensions;
|
|||||||
public static class ReceiverClaimExtensions
|
public static class ReceiverClaimExtensions
|
||||||
{
|
{
|
||||||
private static readonly string[] EnvelopeIdClaimTypes = [EnvelopeClaimTypes.Id, "envelope_id", "EnvelopeId"];
|
private static readonly string[] EnvelopeIdClaimTypes = [EnvelopeClaimTypes.Id, "envelope_id", "EnvelopeId"];
|
||||||
|
private static readonly string[] ReceiverIdClaimTypes = ["receiver_id", "ReceiverId"];
|
||||||
private static readonly string[] EnvelopeUuidClaimTypes = [ClaimTypes.NameIdentifier, "envelope_uuid", "EnvelopeUuid"];
|
private static readonly string[] EnvelopeUuidClaimTypes = [ClaimTypes.NameIdentifier, "envelope_uuid", "EnvelopeUuid"];
|
||||||
private static readonly string[] ReceiverSignatureClaimTypes = [ClaimTypes.Hash, "receiver_sig", "ReceiverSignature"];
|
private static readonly string[] ReceiverSignatureClaimTypes = [ClaimTypes.Hash, "receiver_sig", "ReceiverSignature"];
|
||||||
|
|
||||||
@@ -81,12 +82,29 @@ public static class ReceiverClaimExtensions
|
|||||||
var envIdStr = user.GetRequiredClaimOfReceiver(EnvelopeIdClaimTypes);
|
var envIdStr = user.GetRequiredClaimOfReceiver(EnvelopeIdClaimTypes);
|
||||||
if (!int.TryParse(envIdStr, out var envId))
|
if (!int.TryParse(envIdStr, out var envId))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Claim '{EnvelopeClaimTypes.Id}' is not a valid integer.");
|
throw new InvalidOperationException($"Claim '{"envelope_id"}' is not a valid integer.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return envId;
|
return envId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="InvalidOperationException"></exception>
|
||||||
|
public static int GetReceiverIdOfReceiver(this ClaimsPrincipal user)
|
||||||
|
{
|
||||||
|
var rcvIdStr = user.GetRequiredClaimOfReceiver(ReceiverIdClaimTypes);
|
||||||
|
if (!int.TryParse(rcvIdStr, out var rcvId))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Claim '{"receiver_id"}' is not a valid integer.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return rcvId;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Signs in an envelope receiver using cookie authentication and attaches envelope claims.
|
/// Signs in an envelope receiver using cookie authentication and attaches envelope claims.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user