diff --git a/Endpoint/Common/Services/UrlHelper.cs b/Endpoint/Common/Services/UrlHelper.cs index 923c797..a8ecbd7 100644 --- a/Endpoint/Common/Services/UrlHelper.cs +++ b/Endpoint/Common/Services/UrlHelper.cs @@ -6,7 +6,7 @@ namespace Mirea.Api.Endpoint.Common.Services; public static class UrlHelper { - public static string CurrentDomain(HttpContext context) => + public static string GetCurrentDomain(this HttpContext context) => context.Request.Headers["X-Forwarded-Host"].FirstOrDefault() ?? context.Request.Host.Host; private static string CreateSubPath(string? path) diff --git a/Endpoint/Controllers/Configuration/SetupController.cs b/Endpoint/Controllers/Configuration/SetupController.cs index 2772e4f..45ba240 100644 --- a/Endpoint/Controllers/Configuration/SetupController.cs +++ b/Endpoint/Controllers/Configuration/SetupController.cs @@ -74,9 +74,11 @@ public partial class SetupController( Response.Cookies.Append("AuthToken", token, new CookieOptions { Path = UrlHelper.GetSubPathWithoutFirstApiName + "api", - Domain = UrlHelper.CurrentDomain(ControllerContext.HttpContext), + Domain = HttpContext.GetCurrentDomain(), +#if !DEBUG Secure = true, HttpOnly = true +#endif }); return Ok(true); } diff --git a/Endpoint/Controllers/V1/AuthController.cs b/Endpoint/Controllers/V1/AuthController.cs index f16a596..88154b2 100644 --- a/Endpoint/Controllers/V1/AuthController.cs +++ b/Endpoint/Controllers/V1/AuthController.cs @@ -30,9 +30,11 @@ public class AuthController(IOptionsSnapshot user, AuthService auth, Pass { Expires = expires, Path = UrlHelper.GetSubPathWithoutFirstApiName + "api", - Domain = UrlHelper.CurrentDomain(ControllerContext.HttpContext), + Domain = HttpContext.GetCurrentDomain(), +#if !DEBUG Secure = true, HttpOnly = true +#endif }; Response.Cookies.Append(name, value, cookieOptions);