You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
using Ocelot.Infrastructure.Claims.Parser;
|
|
using Ocelot.Logging;
|
|
using Ocelot.Middleware;
|
|
using Ocelot.Responses;
|
|
|
|
namespace HuiXin.Gateway.Ocelot.Middlewares
|
|
{
|
|
public class MyAuthorizationMiddleware : OcelotMiddleware
|
|
{
|
|
private readonly RequestDelegate _next;
|
|
private readonly IClaimsParser _claimsParser;
|
|
|
|
public MyAuthorizationMiddleware(RequestDelegate next,
|
|
IClaimsParser claimsParser,
|
|
IOcelotLoggerFactory loggerFactory)
|
|
: base(loggerFactory.CreateLogger<MyAuthorizationMiddleware>())
|
|
{
|
|
_next = next;
|
|
_claimsParser = claimsParser;
|
|
}
|
|
|
|
public async Task Invoke(HttpContext httpContext)
|
|
{
|
|
Authorize(httpContext);
|
|
await _next.Invoke(httpContext);
|
|
}
|
|
|
|
public Response<bool> Authorize(HttpContext httpContext)
|
|
{
|
|
var values = _claimsParser.GetValuesByClaimType(httpContext.User.Claims, "role");
|
|
return new OkResponse<bool>(true);
|
|
}
|
|
}
|
|
}
|
|
|