新增了一个获取登陆信息的方法
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user