chore
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using Atomx.Admin.Client.Validators;
|
||||
using Atomx.Admin.Services;
|
||||
using Atomx.Admin.Utils;
|
||||
using Atomx.Common.Constants;
|
||||
using Atomx.Common.Models;
|
||||
using Atomx.Data;
|
||||
@@ -137,33 +136,6 @@ namespace Atomx.Admin.Controllers
|
||||
ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(_jwtSetting.AccessTokenExpirationMinutes)
|
||||
});
|
||||
|
||||
// 另外将 tokens 写入 HttpOnly Cookie(增强与传统中间件的兼容性)
|
||||
try
|
||||
{
|
||||
var cookieOptions = new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
//Secure = !Request.IsLocal(), // 本地调试时允许 http
|
||||
SameSite = SameSiteMode.Lax,
|
||||
Expires = DateTimeOffset.UtcNow.AddMinutes(_jwtSetting.AccessTokenExpirationMinutes),
|
||||
Path = "/"
|
||||
};
|
||||
Response.Cookies.Append("access_token", authResponse.Token, cookieOptions);
|
||||
|
||||
var refreshCookieOptions = new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
//Secure = !Request.IsLocal(),
|
||||
SameSite = SameSiteMode.Lax,
|
||||
Expires = DateTimeOffset.UtcNow.AddMinutes(_jwtSetting.RefreshTokenExpirationMinutes),
|
||||
Path = "/"
|
||||
};
|
||||
Response.Cookies.Append("refresh_token", authResponse.RefreshToken, refreshCookieOptions);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "设置 token cookie 失败(非致命)");
|
||||
}
|
||||
|
||||
return new JsonResult(new ApiResult<AuthResponse>().IsSuccess(authResponse));
|
||||
}
|
||||
@@ -186,34 +158,6 @@ namespace Atomx.Admin.Controllers
|
||||
var ip = _identityService.GetClientIp();
|
||||
var newTokens = await _tokenService.RefreshTokenAsync(request.Token, request.RefreshToken, ip);
|
||||
|
||||
// 更新 cookie(如存在)
|
||||
try
|
||||
{
|
||||
var cookieOptions = new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
//Secure = !Request.IsLocal(),
|
||||
SameSite = SameSiteMode.Lax,
|
||||
Expires = DateTimeOffset.UtcNow.AddMinutes(_jwtSetting.AccessTokenExpirationMinutes),
|
||||
Path = "/"
|
||||
};
|
||||
Response.Cookies.Append("access_token", newTokens.Token, cookieOptions);
|
||||
|
||||
var refreshCookieOptions = new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
//Secure = !Request.IsLocal(),
|
||||
SameSite = SameSiteMode.Lax,
|
||||
Expires = DateTimeOffset.UtcNow.AddMinutes(_jwtSetting.RefreshTokenExpirationMinutes),
|
||||
Path = "/"
|
||||
};
|
||||
Response.Cookies.Append("refresh_token", newTokens.RefreshToken, refreshCookieOptions);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogDebug(ex, "刷新 token 时写 cookie 失败(允许)");
|
||||
}
|
||||
|
||||
return new JsonResult(new ApiResult<AuthResponse>().IsSuccess(newTokens));
|
||||
}
|
||||
catch (SecurityTokenException ex)
|
||||
|
||||
Reference in New Issue
Block a user