we have one service with several deployed instances, each instances serve a group of users. we use this way to do horizontal scaling.
Right now, we want to use gateway as the single api address for all instances, each http request will attach token with claim which indicates the userid. I'm wondering if Ocelot can help on this scenario?
@mogliang thanks for your interest in Ocelot!
At the moment you cannot do this with Ocelot. However it is an interesting idea. I will think about it and get back to you ASAP!
Expected Behavior / New Feature
I'm looking for direction on how to route to a specific downtream resource based on a value in .net identity claim. Ex) user has claim TenantId = "xxx" and this would route them to a specic downstream resource I have setup.
Actual Behavior / Motivation for New Feature
Need to support multi tenant multi site routing with single enpoint visible to user
Steps to Reproduce the Problem
Go to example.com
User would login and get a claim "TenantId": "xxx"
Route is setup to check for "TenantId" claim and route to specific resource based on TenantId value
I managed to get this working with the current version of Ocelot, just by adding a custom AspNetCore middleware before Ocelot in the pipeline:
public class HostNameByTenantHeaderMiddleware
{
private readonly RequestDelegate _next;
public HostNameByTenantHeaderMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
var tenantId = context.Request.Headers["SomeHeaderThatConainsTheTenantId"].ToString();
if (!string.IsNullOrEmpty(tenantId))
{
context.Request.Host = HostString.FromUriComponent(tenantId);
}
await _next(context);
}
}
In your Ocelot.json you can use the UpstreamHost to supply different configurations per tenant.
It should be easy to change this to substract the TenantId from a claim.
Most helpful comment
Expected Behavior / New Feature
I'm looking for direction on how to route to a specific downtream resource based on a value in .net identity claim. Ex) user has claim TenantId = "xxx" and this would route them to a specic downstream resource I have setup.
Actual Behavior / Motivation for New Feature
Need to support multi tenant multi site routing with single enpoint visible to user
Steps to Reproduce the Problem
Go to example.com
User would login and get a claim "TenantId": "xxx"
Route is setup to check for "TenantId" claim and route to specific resource based on TenantId value