diff --git a/docs/features/middlewareinjection.rst b/docs/features/middlewareinjection.rst index 7fccc599b..2068a8e9a 100644 --- a/docs/features/middlewareinjection.rst +++ b/docs/features/middlewareinjection.rst @@ -35,6 +35,8 @@ The user can set functions against the following. * AuthorizationMiddleware - This overrides Ocelots authorization middleware. +* ClaimsToHeadersMiddleware - This overrides Ocelots claims to headers middleware. + * PreQueryStringBuilderMiddleware - This allows the user to manipulate the query string on the http request before it is passed to Ocelots request creator. Obviously you can just add middleware as normal before the call to app.UseOcelot() It cannot be added diff --git a/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs b/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs index 012dc9ed7..7da206594 100644 --- a/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs +++ b/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs @@ -1,10 +1,9 @@ -using System; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; - namespace Ocelot.Middleware { public class OcelotPipelineConfiguration @@ -59,6 +58,14 @@ public class OcelotPipelineConfiguration /// public Func, Task> PreQueryStringBuilderMiddleware { get; set; } + /// + /// This allows the user to completely override the Ocelot's Claims to Headers middleware. + /// + /// + /// A delegate object. + /// + public Func, Task> ClaimsToHeadersMiddleware { get; set; } + /// /// This is an extension that will branch to different pipes. /// diff --git a/src/Ocelot/Middleware/OcelotPipelineExtensions.cs b/src/Ocelot/Middleware/OcelotPipelineExtensions.cs index e804ce1af..febad2d1b 100644 --- a/src/Ocelot/Middleware/OcelotPipelineExtensions.cs +++ b/src/Ocelot/Middleware/OcelotPipelineExtensions.cs @@ -1,11 +1,5 @@ -using System; -using System.Threading.Tasks; - -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; - -using Ocelot.Multiplexer; - using Ocelot.Authentication.Middleware; using Ocelot.Authorization.Middleware; using Ocelot.Cache.Middleware; @@ -16,6 +10,7 @@ using Ocelot.Errors.Middleware; using Ocelot.Headers.Middleware; using Ocelot.LoadBalancer.Middleware; +using Ocelot.Multiplexer; using Ocelot.QueryStrings.Middleware; using Ocelot.RateLimit.Middleware; using Ocelot.Request.Middleware; @@ -24,6 +19,8 @@ using Ocelot.Responder.Middleware; using Ocelot.Security.Middleware; using Ocelot.WebSockets.Middleware; +using System; +using System.Threading.Tasks; namespace Ocelot.Middleware { @@ -124,8 +121,16 @@ public static class OcelotPipelineExtensions app.Use(pipelineConfiguration.AuthorizationMiddleware); } - // Now we can run the claims to headers transformation middleware - app.UseClaimsToHeadersMiddleware(); + // Now we can run the claims to headers transformation middleware. + // We allow the ocelot middleware to be overriden by whatever the user wants + if (pipelineConfiguration.ClaimsToHeadersMiddleware == null) + { + app.UseClaimsToHeadersMiddleware(); + } + else + { + app.Use(pipelineConfiguration.ClaimsToHeadersMiddleware); + } // Allow the user to implement their own query string manipulation logic app.UseIfNotNull(pipelineConfiguration.PreQueryStringBuilderMiddleware);