update to use ClaimsPrincipal instead of ControllerBase

This commit is contained in:
tekh 2025-08-22 22:29:51 +02:00
parent 6778d8e3e7
commit 0b33ba0fd8
3 changed files with 14 additions and 14 deletions

View File

@ -10,21 +10,21 @@ namespace EnvelopeGenerator.Web.Controllers
public static class ControllerBaseExtensions
{
#region Auth
public static string? GetClaimValue(this ControllerBase controller, string claimType) => controller.User.FindFirstValue(claimType);
public static string? GetClaimValue(this ClaimsPrincipal user, string claimType) => user.FindFirstValue(claimType);
public static string? GetAuthEnvelopeUuid(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.NameIdentifier);
public static string? GetAuthEnvelopeUuid(this ClaimsPrincipal user) => user.FindFirstValue(ClaimTypes.NameIdentifier);
public static string? GetAuthReceiverSignature(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Hash);
public static string? GetAuthReceiverSignature(this ClaimsPrincipal user) => user.FindFirstValue(ClaimTypes.Hash);
public static string? GetAuthReceiverName(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Name);
public static string? GetAuthReceiverName(this ClaimsPrincipal user) => user.FindFirstValue(ClaimTypes.Name);
public static string? GetAuthReceiverMail(this ControllerBase controller) => controller.User.FindFirstValue(ClaimTypes.Email);
public static string? GetAuthReceiverMail(this ClaimsPrincipal user) => user.FindFirstValue(ClaimTypes.Email);
public static string? GetAuthEnvelopeTitle(this ControllerBase controller) => controller.User.FindFirstValue(EnvelopeClaimTypes.Title);
public static string? GetAuthEnvelopeTitle(this ClaimsPrincipal user) => user.FindFirstValue(EnvelopeClaimTypes.Title);
public static int? GetAuthEnvelopeId(this ControllerBase controller)
public static int? GetAuthEnvelopeId(this ClaimsPrincipal user)
{
var env_id_str = controller.User.FindFirstValue(EnvelopeClaimTypes.Id);
var env_id_str = user.FindFirstValue(EnvelopeClaimTypes.Id);
return int.TryParse(env_id_str, out int env_id) ? env_id : null;
}

View File

@ -63,7 +63,7 @@ public class EnvelopeController : BaseController
{
envelopeKey = _urlEncoder.Encode(envelopeKey);
var authSignature = this.GetAuthReceiverSignature();
var authSignature = User.GetAuthReceiverSignature();
if (authSignature != envelopeKey.GetReceiverSignature())
return Unauthorized();
@ -98,9 +98,9 @@ public class EnvelopeController : BaseController
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public async Task<IActionResult> Reject([FromBody] string? reason = null)
{
var signature = this.GetAuthReceiverSignature();
var uuid = this.GetAuthEnvelopeUuid();
var mail = this.GetAuthReceiverMail();
var signature = User.GetAuthReceiverSignature();
var uuid = User.GetAuthEnvelopeUuid();
var mail = User.GetAuthReceiverMail();
if (uuid is null || signature is null || mail is null)
{
_logger.LogEnvelopeError(uuid: uuid, signature: signature,

View File

@ -38,14 +38,14 @@ namespace EnvelopeGenerator.Web.Controllers
public async Task<IActionResult> CreateAsync([FromBody] EnvelopeReceiverReadOnlyCreateDto createDto)
{
//set AddedWho
var authReceiverMail = this.GetAuthReceiverMail();
var authReceiverMail = User.GetAuthReceiverMail();
if (authReceiverMail is null)
{
_logger.LogError("EmailAddress clam is not found in envelope-receiver-read-only creation process. Create DTO is:\n {dto}", JsonConvert.SerializeObject(createDto));
return Unauthorized();
}
var envelopeId = this.GetAuthEnvelopeId();
var envelopeId = User.GetAuthEnvelopeId();
if (envelopeId is null)
{
_logger.LogError("Envelope Id clam is not found in envelope-receiver-read-only creation process. Create DTO is:\n {dto}", JsonConvert.SerializeObject(createDto));