refactor: distribute the domain folder
This commit is contained in:
29
Security/Common/Model/CookieOptions.cs
Normal file
29
Security/Common/Model/CookieOptions.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
|
||||
namespace Mirea.Api.Security.Common.Model;
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user