Finbuckle / Finbuckle.MultiTenant

Finbuckle.MultiTenant is an open-source multitenancy middleware library for .NET. It enables tenant resolution, per-tenant app behavior, and per-tenant data isolation.
https://www.finbuckle.com/multitenant
Apache License 2.0
1.31k stars 267 forks source link

ConfigurePerTenant Issue #828

Open goforebroke opened 4 months ago

goforebroke commented 4 months ago

Hi Andrew,

I just upgraded to your latest release. I have gone through your docs, updating sections of my code. I am now having issues now redirecting to my identity server authority with the TENANT in the URL

Prior to the upgrade, one of my razor projects would redirect nicely to identity server authority with the TENANT in the URL

Below is the old way of registering the Finbuckle components in my Razor page project.

 private static void AddMultiTenantServices(IServiceCollection services,
        IConfiguration configuration)
    {
        var identityUrl = configuration["IdentityUrl"] ??
              throw new ArgumentNullException(nameof(configuration),
                  "Identity url is null or empty");

        var callBackUrl = configuration["CallBackUrl"] ??
                          throw new ArgumentNullException(nameof(configuration),
                              "Callback url is null or empty");

        var httpRemoteStore = configuration.GetRequiredSection("TenantRemoteStore:Url").Value ??
                          throw new ArgumentNullException(nameof(configuration),
            "Tenant remote store is null or empty");

        services.AddMultiTenant<AppTenantInfo>()
            .WithBasePathStrategy(options =>
            {
                options.RebaseAspNetCorePathBase = true;
            })
            .WithStaticStrategy("dssports")
            .WithHttpRemoteStore(httpRemoteStore, options =>
            {
                options.AddHttpMessageHandler<CorrelationIdDelegatingHandler>();
            })
            .WithPerTenantAuthentication()
            .WithPerTenantOptions<OpenIdConnectOptions>((options, tenantInfo) =>
            {
                options.Authority = $"{identityUrl}/{tenantInfo.Identifier}";
                options.SignedOutRedirectUri = $"{callBackUrl}/{tenantInfo.Identifier}";
            });
    }

The per tenant options would nicely redirect to the identity server => http://idsurl/TENANT/

After the upgrade, I updated my code per the documentation

Registering Finbuckle components in Razor page project after the upgrade....

   private static void AddMultiTenantServices(IServiceCollection services,
       IConfiguration configuration)
   {
       var identityUrl = configuration["IdentityUrl"] ??
             throw new ArgumentNullException(nameof(configuration),
                 "Identity url is null or empty");

       var callBackUrl = configuration["CallBackUrl"] ??
                         throw new ArgumentNullException(nameof(configuration),
                             "Callback url is null or empty");

       var httpRemoteStore = configuration.GetRequiredSection("TenantRemoteStore:Url").Value ??
                         throw new ArgumentNullException(nameof(configuration),
           "Tenant remote store is null or empty");

       services.AddMultiTenant<AppTenantInfo>()
           .WithBasePathStrategy(options =>
           {
               options.RebaseAspNetCorePathBase = true;
           })
           .WithStaticStrategy("dssports")
           .WithHttpRemoteStore(httpRemoteStore, options =>
           {
               options.AddHttpMessageHandler<RequestIdDelegatingHandler>();
           })
           .WithPerTenantAuthentication();

           services.ConfigurePerTenant<OpenIdConnectOptions, AppTenantInfo>((options, tenantInfo) =>
           {
               options.Authority = $"{identityUrl}/{tenantInfo.Identifier}";;
               options.SignedOutRedirectUri = $"{callBackUrl}/{tenantInfo.Identifier}";
           });
   }

Now every redirect does not contain the TENANT in the URL => http://idsurl/

goforebroke commented 4 months ago

I went through your source code... MultiTenantBuilderExtensions, and updated my code to below... All is working as before

            services.ConfigureAllPerTenant<OpenIdConnectOptions, AppTenantInfo>((options, tenantInfo) =>
            {
                options.Authority = $"{identityUrl}/{tenantInfo.Identifier}";
                options.SignedOutRedirectUri = $"{callBackUrl}/{tenantInfo.Identifier}";
            });
AndrewTriesToCode commented 4 months ago

You beat me to it. Alternatively you can provide the scheme name as the option name.