diff --git a/EnvelopeGenerator.API/Controllers/CacheController.cs b/EnvelopeGenerator.API/Controllers/CacheController.cs index e1da376a..8b15dc46 100644 --- a/EnvelopeGenerator.API/Controllers/CacheController.cs +++ b/EnvelopeGenerator.API/Controllers/CacheController.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Options; using System.Text.Json; using EnvelopeGenerator.API.Options; using EnvelopeGenerator.Domain.Constants; +using EnvelopeGenerator.API.Extensions; namespace EnvelopeGenerator.API.Controllers; @@ -18,18 +19,19 @@ public class CacheController( IDistributedCache cache, IOptions cacheOptions) : ControllerBase { - private const string SignatureCacheKeyPrefix = "signature:91751687-8ae6-4777-bf5f-b8846085e62e:"; + private const string SignatureCacheKeyPrefix = "envelope-generator.receiver-ui.signature:"; /// /// Stores a receiver's signature in cache for the specified envelope. /// + [Authorize(Policy = AuthPolicy.Receiver)] [HttpPost("SignatureCapture/{envelopeKey}")] public async Task SaveSignature( - string envelopeKey, + [FromRoute] string envelopeKey, [FromBody] SignatureCacheRequest request, CancellationToken cancel) { - var cacheKey = $"{SignatureCacheKeyPrefix}{envelopeKey}"; + var cacheKey = $"{SignatureCacheKeyPrefix}{User.ReceiverSignature}"; var json = JsonSerializer.Serialize(request); var options = cacheOptions.Value.SignatureCacheExpiration.HasValue @@ -44,10 +46,11 @@ public class CacheController( /// /// Retrieves a cached signature for the specified envelope. /// + [Authorize(Policy = AuthPolicy.Receiver)] [HttpGet("SignatureCapture/{envelopeKey}")] - public async Task GetSignature(string envelopeKey, CancellationToken cancel) + public async Task GetSignature([FromRoute] string envelopeKey, CancellationToken cancel) { - var cacheKey = $"{SignatureCacheKeyPrefix}{envelopeKey}"; + var cacheKey = $"{SignatureCacheKeyPrefix}{User.ReceiverSignature}"; var json = await cache.GetStringAsync(cacheKey, cancel); if (json is null) @@ -60,10 +63,11 @@ public class CacheController( /// /// Deletes a cached signature for the specified envelope. /// + [Authorize(Policy = AuthPolicy.Receiver)] [HttpDelete("SignatureCapture/{envelopeKey}")] - public async Task DeleteSignature(string envelopeKey, CancellationToken cancel) + public async Task DeleteSignature([FromRoute] string envelopeKey, CancellationToken cancel) { - var cacheKey = $"{SignatureCacheKeyPrefix}{envelopeKey}"; + var cacheKey = $"{SignatureCacheKeyPrefix}{User.ReceiverSignature}"; await cache.RemoveAsync(cacheKey, cancel); return Ok(); @@ -74,9 +78,7 @@ public class CacheController( /// Request model for caching signature data. /// public sealed record SignatureCacheRequest( - string? DataUrl, - string? FullName, - string? Position, - string? Place); - - + string DataUrl, + string FullName, + string Place, + string? Position = null); \ No newline at end of file