|
|
|
@ -4,15 +4,15 @@ using System.Text.RegularExpressions; |
|
|
|
|
using Tiobon.Core.Caches; |
|
|
|
|
using Tiobon.Core.Helper; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.AuthHelper |
|
|
|
|
namespace Tiobon.Core.AuthHelper; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 中间件 |
|
|
|
|
/// 原做为自定义授权中间件 |
|
|
|
|
/// 先做检查 header token的使用 |
|
|
|
|
/// </summary> |
|
|
|
|
public class CustomJwtTokenAuthMiddleware |
|
|
|
|
{ |
|
|
|
|
/// <summary> |
|
|
|
|
/// 中间件 |
|
|
|
|
/// 原做为自定义授权中间件 |
|
|
|
|
/// 先做检查 header token的使用 |
|
|
|
|
/// </summary> |
|
|
|
|
public class CustomJwtTokenAuthMiddleware |
|
|
|
|
{ |
|
|
|
|
private readonly ICaching _cache; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -27,7 +27,7 @@ namespace Tiobon.Core.AuthHelper |
|
|
|
|
private readonly RequestDelegate _next; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CustomJwtTokenAuthMiddleware(RequestDelegate next, IAuthenticationSchemeProvider schemes, AppSettings appset,ICaching cache) |
|
|
|
|
public CustomJwtTokenAuthMiddleware(RequestDelegate next, IAuthenticationSchemeProvider schemes, AppSettings appset, ICaching cache) |
|
|
|
|
{ |
|
|
|
|
_cache = cache; |
|
|
|
|
_next = next; |
|
|
|
@ -50,12 +50,12 @@ namespace Tiobon.Core.AuthHelper |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
//黑名单验证 |
|
|
|
|
if(CheckBlackList(questUrl)) |
|
|
|
|
if (CheckBlackList(questUrl)) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<PermissionItem> Permissions= new(); |
|
|
|
|
List<PermissionItem> Permissions = new(); |
|
|
|
|
|
|
|
|
|
httpContext.Features.Set<IAuthenticationFeature>(new AuthenticationFeature |
|
|
|
|
{ |
|
|
|
@ -97,20 +97,20 @@ namespace Tiobon.Core.AuthHelper |
|
|
|
|
if (currentUserRoles.Count <= 0 || !isMatchRole) |
|
|
|
|
{ |
|
|
|
|
await httpContext.Cof_SendResponse(HttpStatusCode.ServiceUnavailable, "未授权此资源"); |
|
|
|
|
return ; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
await httpContext.Cof_SendResponse(HttpStatusCode.Unauthorized, "请重新登录"); |
|
|
|
|
return ; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
await httpContext.Cof_SendResponse(HttpStatusCode.Unauthorized, "系统鉴权出错"); |
|
|
|
|
return ; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
await _next.Invoke(httpContext); |
|
|
|
|
} |
|
|
|
@ -175,11 +175,10 @@ namespace Tiobon.Core.AuthHelper |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class Urlobj |
|
|
|
|
{ |
|
|
|
|
public class Urlobj |
|
|
|
|
{ |
|
|
|
|
public string url { get; set; } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|