Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigurePerTenant Issue #828

Open
goforebroke opened this issue May 18, 2024 · 2 comments
Open

ConfigurePerTenant Issue #828

goforebroke opened this issue May 18, 2024 · 2 comments
Labels

Comments

@goforebroke
Copy link

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
Copy link
Author

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
Copy link
Sponsor Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants