Files
mixtape/zero.Core/Security/ContextualCookieManager.cs
T
2020-11-04 16:16:36 +01:00

27 lines
712 B
C#

using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Http;
using System;
namespace zero.Core.Security
{
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);
}
}
}