Finbuckle.MultiTenant icon indicating copy to clipboard operation
Finbuckle.MultiTenant copied to clipboard

Error 404 NotFound with Pathbase Strategies

Open HDScarpe opened this issue 2 years ago • 1 comments

Hello. I use Finbuckle.MultiTenant library with Duende. Currently I am using PathBase Strategy to define tenants. I have successfully identified the tenant on login. However after successful login i call the controller swagger then i have 2 problems and question 1: Can I use ClaimStrategies to identify tenants after login. Currently I cannot use ClaimStrategies to determine after successful login even though I call it in AddMultiTenant like the following code

 return services
             .AddDbContext<TenantDbContext>(options => options
                 .UseSqlServer(connectionString))
             .AddMultiTenant<ScarpeTenant>()
             .WithBasePathStrategy(
                 ctx =>
                 {
                     ctx.RebaseAspNetCorePathBase = true;
                 }) 
             .WithClaimStrategy("tenantid")
             .WithHeaderStrategy(SystemConstants.TenantIdName)
             .WithEFCoreStore<TenantDbContext, ScarpeTenant>()
             .WithPerTenantAuthentication()
             .Services; 

2: Since ClaimStrategies couldn't be used on its own in issue 1. So I added the tenant parameter at the top of the api (as shown in figure). However, after entering the correct tenant "root" Got a 404 NotFound error and could not call the controller. I don't understand what it means to get a 404 NotFound. If I reluctantly enter a non-existent tenant as "root1", the controller successfully calls back.

  1. entering the correct tenant "root" image

  2. enter a non-existent tenant as "root1" image

Here is all my code . You can view and reply to me. Thank you.

HDScarpe avatar Feb 08 '23 10:02 HDScarpe

Hi, for the Claims strategy you have to make sure IdentityServer (and internally ASP.NET Core Identity) are setting a tenant claim on the principle it generates. I'm snot sure from you code if you have it doing that or not.

With regard to BasePath strategy -- Swagger won't show the base path because it won't even see it. If the multitenant middleware detects the tenant from the base path it will adjust the base path (if you are using this option) so that subsequent middleware will only see the remaining path -- so your route parameter there wouldn't see any tenant. From your API's perspective it should define routes as if the tenant base path isn't there. Any calls to the URI will reality have the tenant base path so when the API is called it's active tenant should be correct. I hope that makes sense.

AndrewTriesToCode avatar Feb 17 '23 05:02 AndrewTriesToCode