ABP 7.0.1 Commercial / Blazor Server / EF / Separated IDS / Non-tiered
Hi, We extended the tenant entity to add a "Host" column which stores a tenant specific subdomain for each tenant (tenant1.domain.com) by following https://blog.antosubash.com/posts/abp-extend-tenant-with-custom-host
We then implemented the following tenant resolver:
public override async Task ResolveAsync(ITenantResolveContext context)
{
var currentContextAccessor = context.ServiceProvider.GetRequiredService<IHttpContextAccessor>();
var tenantRepository = context.ServiceProvider.GetRequiredService<IHostTenantRepository>();
var host = currentContextAccessor?.HttpContext?.Request.Host.Host;
host = GetSubDomain(host);
if (tenantRepository != null && !host.IsNullOrWhiteSpace())
{
var tenant = await tenantRepository.GetTenantByHost(host);
if (tenant != null)
{
context.TenantIdOrName = tenant.Name;
}
}
}
Everything works as expected as we can login to each tenant with a tenant specific subdomain in the URL.
The problem we are finding though is that if we attempt to impersonate a tenant from the host, we are not redirected to the tenant's URL (tenant1.domain.com) instead we stay at at the host URL with no subdomain (domain.com).
Has this tenant impersonation issue ever come up with a basic tenant resolver based on subdomain? Any guidance, examples, or work arounds will be greatly appreciated as tenant impersonation and a custom tenant resolver are both requirements for us.
13 Answer(s)
-
0
hi
please share your project structure screenshot, thanks
-
0
-
0
-
0
Thanks @maliming,
I will try the page overrides and let you know how that works.
In the meantime, can you explain this in more detail?
This requires sharing cookies between the subdomain and the main domain name.
I have limited experience with cookie management and am wondering if there are possible issues or workarounds to consider.
-
0
hi
I have limited experience with cookie management and am wondering if there are possible issues or workarounds to consider.
something like this https://gist.github.com/maliming/b1ea80d68982a5b7064d7df6bafa89f5
-
0
Hi @maliming,
We are not having any success. We successfully replaced TenantManagment.razor. From there, it wasn't exactly clear to us on how to correctly add the tenant's domain to the action of ImpersonationForm, so for a proof of concept, we hardcoded the action URL as follows:
Once we did this and then attempted to impersonate the tenant, we are directed to the login screen for that tenant (instead of instantly being logged in as the tenant). When we then try to login to the tenant, we receive the following error:
Impersonating a user within a tenant works fine because everything is under the same sub domain URL.
We also tried overriding the
OnPostAsync()
method ofImpersonateTenantModel
and changedreturn Redirect("~/");
to direct to the tenant's sub domain URL, and this seems to work, but the 'return to impersonator' link no longer appears and were not sure this is the correct way of implementing tenant impersonation with each tenant having it's own subdomain. -
0
hi
I will check and find a way.
-
0
hi
I will check and find a way.
Excellent, thank you @mailiming
-
0
-
0
Hi @maliming,
I sent you a direct email with details for reproducing/troubleshooting...
-
0
OK, I will check it asap.
-
0
hi
https://github.com/balessi75/FM.Test/issues/1
-
0
Hi @maliming,
Just wanted to thank you for the quick turnaround on this issue. Your solution worked perfectly. Thank you, we appreciate the support!