新增了一个获取登陆信息的方法

This commit is contained in:
2024-03-24 17:31:22 +08:00
parent 99b26d99f6
commit 8344567ac6
2 changed files with 19 additions and 3 deletions
+4 -3
View File
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Distributed;
using SimApi.Communications;
using SimApi.Helpers;
namespace SimApi.Middlewares;
@@ -11,7 +12,7 @@ namespace SimApi.Middlewares;
/// </summary>
public class SimApiAuthMiddleware(RequestDelegate next)
{
public Task Invoke(HttpContext httpContext, IDistributedCache cache)
public Task Invoke(HttpContext httpContext, IDistributedCache cache, SimApiAuth auth)
{
string token = null;
if (httpContext.Request.Headers.TryGetValue("Token", out var header))
@@ -21,10 +22,10 @@ public class SimApiAuthMiddleware(RequestDelegate next)
if (!string.IsNullOrEmpty(token))
{
var login = cache.GetString(token);
var login = auth.GetLogin(token);
if (login != null)
{
httpContext.Items.Add("LoginInfo", JsonSerializer.Deserialize<SimApiLoginItem>(login));
httpContext.Items.Add("LoginInfo", login);
}
}