2024-10-31 04:12:02 +03:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using System;
|
|
|
|
|
|
2024-12-26 13:38:43 +03:00
|
|
|
|
namespace Mirea.Api.Security.Common.Model;
|
2024-10-31 04:12:02 +03:00
|
|
|
|
|
2024-12-26 13:38:43 +03:00
|
|
|
|
public class CookieOptions
|
2024-10-31 04:12:02 +03:00
|
|
|
|
{
|
|
|
|
|
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
|
2024-10-31 04:12:02 +03:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|