refactor: use this in static method
This commit is contained in:
parent
c51a9cecc9
commit
b1250616a7
@ -6,7 +6,7 @@ namespace Mirea.Api.Endpoint.Common.Services;
|
|||||||
|
|
||||||
public static class UrlHelper
|
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;
|
context.Request.Headers["X-Forwarded-Host"].FirstOrDefault() ?? context.Request.Host.Host;
|
||||||
|
|
||||||
private static string CreateSubPath(string? path)
|
private static string CreateSubPath(string? path)
|
||||||
|
@ -74,9 +74,11 @@ public partial class SetupController(
|
|||||||
Response.Cookies.Append("AuthToken", token, new CookieOptions
|
Response.Cookies.Append("AuthToken", token, new CookieOptions
|
||||||
{
|
{
|
||||||
Path = UrlHelper.GetSubPathWithoutFirstApiName + "api",
|
Path = UrlHelper.GetSubPathWithoutFirstApiName + "api",
|
||||||
Domain = UrlHelper.CurrentDomain(ControllerContext.HttpContext),
|
Domain = HttpContext.GetCurrentDomain(),
|
||||||
|
#if !DEBUG
|
||||||
Secure = true,
|
Secure = true,
|
||||||
HttpOnly = true
|
HttpOnly = true
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,11 @@ public class AuthController(IOptionsSnapshot<Admin> user, AuthService auth, Pass
|
|||||||
{
|
{
|
||||||
Expires = expires,
|
Expires = expires,
|
||||||
Path = UrlHelper.GetSubPathWithoutFirstApiName + "api",
|
Path = UrlHelper.GetSubPathWithoutFirstApiName + "api",
|
||||||
Domain = UrlHelper.CurrentDomain(ControllerContext.HttpContext),
|
Domain = HttpContext.GetCurrentDomain(),
|
||||||
|
#if !DEBUG
|
||||||
Secure = true,
|
Secure = true,
|
||||||
HttpOnly = true
|
HttpOnly = true
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
Response.Cookies.Append(name, value, cookieOptions);
|
Response.Cookies.Append(name, value, cookieOptions);
|
||||||
|
Loading…
Reference in New Issue
Block a user