-
Imagine a scenario (I know it seems odd but unfortunately it’s real!) that clients want to use one upstream (e.g., http://api.qwe.com/v1/sms) to send SMS with some SMS providers, but in the background it automatically identifies the related subservice based on the public void Configure(IApplicationBuilder app)
{
var conf = new OcelotPipelineConfiguration
{
PreAuthorizationMiddleware = async (httpContext, next) =>
{
var claims = httpContext.User.Claims;
if (claims != null)
{
var scopes = claims.Where(x => x.Type == "scope").Select(x => x.Value);
if (scopes != null)
{
// Override the downstream request settings
var downstreamRequest = httpContext.Items.DownstreamRequest();
downstreamRequest.Host = downstreamRequest.Host;
downstreamRequest.Port = downstreamRequest.Port;
downstreamRequest.Scheme = downstreamRequest.Scheme;
// DO OTHER THINGS
}
}
}
};
builder.Services.AddOcelot(conf).AddConsul();
} As it shows, they use The main question How can I tell Ocelot to use Consul instead of Host:Port?If you have a moment, I’d appreciate your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi Shadman! Short answer: Use Service discovery!First,You don't have to override Second,Classic approach of overriding of overwriting something in Ocelot is Delegating Handlers feature. Most of user scenarios can be implemented using delegating handler. Third,I believe to implement your user scenario you need to
Good luck! |
Beta Was this translation helpful? Give feedback.
Hi Shadman!
Welcome to Ocelot world! 🐯
Short answer: Use Service discovery!
First,
You don't have to override
PreAuthorizationMiddleware
! You need to develop a kind of dynamic routing vs Consul solution...Also, you can read
httpContext.User.Claims
from any class after authentication passed, so you need just to define authenticated route to have claims.Second,
Classic approach of overriding of overwriting something in Ocelot is Delegating Handlers feature. Most of user scenarios can be implemented using delegating handler.
But your scenario is quite complicated! You want to use dynamic routing, and Consul. See the next point!
Third,
I believe to implement your user scenario you need to