feat(EnvelopeCookieManager): add EnvelopeCookieManager to support envelope-specific cookie names
- Introduce EnvelopeCookieManager wrapper around ChunkingCookieManager to generate dynamic cookie names based on envelopeReceiverId or envKey. Ensures request/response cookies are scoped per envelope.
This commit is contained in:
parent
e66c46767e
commit
b088eb089f
49
EnvelopeGenerator.Web/EnvelopeCookieManager.cs
Normal file
49
EnvelopeGenerator.Web/EnvelopeCookieManager.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Web;
|
||||||
|
|
||||||
|
public class EnvelopeCookieManager : ICookieManager
|
||||||
|
{
|
||||||
|
private readonly IEnumerable<string> _envelopeKeyBasedCookieNames;
|
||||||
|
|
||||||
|
private readonly ChunkingCookieManager _inner = new();
|
||||||
|
|
||||||
|
public EnvelopeCookieManager(params string[] envelopeKeyBasedCookieNames)
|
||||||
|
{
|
||||||
|
_envelopeKeyBasedCookieNames = envelopeKeyBasedCookieNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetCookieName(HttpContext context, string key)
|
||||||
|
{
|
||||||
|
if (!_envelopeKeyBasedCookieNames.Contains(key))
|
||||||
|
return key;
|
||||||
|
|
||||||
|
var envId = context.GetRouteValue("envelopeReceiverId")?.ToString();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(envId) && context.Request.Query.TryGetValue("envKey", out var envKeyValue))
|
||||||
|
envId = envKeyValue;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(envId))
|
||||||
|
return key;
|
||||||
|
|
||||||
|
return $"{key}-{envId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? GetRequestCookie(HttpContext context, string key)
|
||||||
|
{
|
||||||
|
var cookieName = GetCookieName(context, key);
|
||||||
|
return _inner.GetRequestCookie(context, cookieName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AppendResponseCookie(HttpContext context, string key, string? value, CookieOptions options)
|
||||||
|
{
|
||||||
|
var cookieName = GetCookieName(context, key);
|
||||||
|
_inner.AppendResponseCookie(context, cookieName, value, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteCookie(HttpContext context, string key, CookieOptions options)
|
||||||
|
{
|
||||||
|
var cookieName = GetCookieName(context, key);
|
||||||
|
_inner.DeleteCookie(context, cookieName, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user