2021-11-19 16:11:12 +01:00
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
2021-11-20 13:52:28 +01:00
|
|
|
namespace zero.Identity;
|
2021-11-19 16:11:12 +01:00
|
|
|
|
|
|
|
|
public class ContextualCookieManager : ChunkingCookieManager, ICookieManager
|
|
|
|
|
{
|
|
|
|
|
protected Func<HttpContext, string, bool> Validate { get; private set; } = (ctx, key) => true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ContextualCookieManager(Func<HttpContext, string, bool> onValidate)
|
|
|
|
|
{
|
|
|
|
|
Validate = onValidate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Explicitly implement this so that we filter the request
|
|
|
|
|
/// </summary>
|
|
|
|
|
string ICookieManager.GetRequestCookie(HttpContext context, string key)
|
|
|
|
|
{
|
|
|
|
|
return !Validate(context, key) ? null : GetRequestCookie(context, key);
|
|
|
|
|
}
|
|
|
|
|
}
|