From b1250616a79236132e4e83986357b1c58f96ca3f Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sat, 10 Aug 2024 23:11:43 +0300 Subject: [PATCH] refactor: use this in static method --- Endpoint/Common/Services/UrlHelper.cs | 2 +- Endpoint/Controllers/Configuration/SetupController.cs | 4 +++- Endpoint/Controllers/V1/AuthController.cs | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) 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);