Ocelot: Claim based routing / partition routing

Created on 10 Jul 2018  路  3Comments  路  Source: ThreeMammals/Ocelot

Expected Behavior / New Feature

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?

Actual Behavior / Motivation for New Feautre

Specifications

  • Version:
  • Platform:
  • Subsystem:
enhancement good first issue help wanted large effort

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

All 3 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ruimaciel picture ruimaciel  路  3Comments

mkanakis picture mkanakis  路  3Comments

jefferson picture jefferson  路  3Comments

LuketaD2 picture LuketaD2  路  3Comments

mjrousos picture mjrousos  路  6Comments