MireaBackend/Security/Common/Model/CookieOptions.cs

30 lines
792 B
C#
Raw Normal View History

using Microsoft.AspNetCore.Http;
using System;
2024-12-26 13:38:43 +03:00
namespace Mirea.Api.Security.Common.Model;
2024-12-26 13:38:43 +03:00
public class CookieOptions
{
public required string Domain { get; set; }
public required string Path { get; set; }
internal void SetCookie(HttpContext context, string name, string value, DateTimeOffset? expires = null)
{
2024-12-26 13:38:43 +03:00
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions
{
Expires = expires,
Path = Path,
Domain = Domain,
HttpOnly = true,
#if !DEBUG
Secure = true
#endif
};
context.Response.Cookies.Append(name, value, cookieOptions);
}
internal void DropCookie(HttpContext context, string name) =>
SetCookie(context, name, "", DateTimeOffset.MinValue);
}