Files
StopShopping/StopShopping.Api/Extensions/HttpExtensions.cs
2026-03-25 14:55:34 +08:00

37 lines
896 B
C#

using StopShopping.Services.Extensions;
namespace Microsoft.AspNetCore.Http;
public static class HttpExtensions
{
public const string REFRESH_TOKEN_COOKIE_KEY = "refresh_token";
public static IResponseCookies AppendRefreshToken(
this IResponseCookies cookies,
IWebHostEnvironment env,
AppOptions appOptions,
TimeSpan maxAge,
string token)
{
CookieOptions options = new()
{
MaxAge = maxAge,
HttpOnly = true,
SameSite = SameSiteMode.Lax,
};
if (!env.IsDevelopment())
{
options.SameSite = SameSiteMode.None;
options.Secure = true;
options.Domain = appOptions.CookieDomain;
}
cookies.Append(
REFRESH_TOKEN_COOKIE_KEY,
token,
options);
return cookies;
}
}