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()) { _next = next; _claimsParser = claimsParser; } public async Task Invoke(HttpContext httpContext) { Authorize(httpContext); await _next.Invoke(httpContext); } public Response Authorize(HttpContext httpContext) { var values = _claimsParser.GetValuesByClaimType(httpContext.User.Claims, "role"); return new OkResponse(true); } } }