Identity client is used for front-end (angular, mvc, blazor, console....), not Tenant.
Ok, this makes sense. So what is the recommended approach within the ABP framework if I wanted to extend some of the API functionality to tenants?
We are using the commercial module to build out our client portal, but we would like to extend certain API access to clients directly for them to consume. So, my question is:
I can see and have created OAuth2 clients in the Identity Server -> Clients section, but the documentation assumes a level of understanding of this identity server that I just do not have. So, is there a specific set of claims or anything on the "Advanced" tab that I can set inside the current UI setup in order to restrict a specific connection to a specific TenantId?
Not sure if this will be made public, but the solution I landed on was overriding the FindByNameAsync
method in the EfCoreTenantRepository
class so that the tenant creation process and the the domain resolver will both be operating out of the same playbook.
It's probably not the most efficient code, but this is what that override class looks like now:
[Dependency(ReplaceServices = true)]
public class CustomTenantRepository : EfCoreTenantRepository
{
public CustomTenantRepository(IDbContextProvider<ISaasDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public override async Task<Tenant> FindByNameAsync(string name, bool includeDetails = true, CancellationToken cancellationToken = default)
{
var tenants = await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.OrderBy(t => t.Id).ToListAsync();
return tenants
.FirstOrDefault(t => (t.Name == name || TestUrlNamingConvention(t.Name,name)));
}
private bool TestUrlNamingConvention(string tenantName, string inputName)
{
var i = string.Concat(inputName.Where(c => !char.IsWhiteSpace(c))).ToLowerInvariant();
var t = string.Concat(tenantName.Where(c => !char.IsWhiteSpace(c))).ToLowerInvariant();
return i == t;
}
}
And because I often find myself asking where I should put these, I have mine in the Project.EntityFrameworkCore
project.
hi
You can custom the
DomainTenantResolveContributor
.https://docs.abp.io/en/abp/latest/Multi-Tenancy#custom-tenant-resolvers
https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/DomainTenantResolveContributor.cs
That is where I started, and the domain tenant resolver does successfully match the domain value (in this case norules) from the URL but I am then pushed to a screen that simply states:
Tenant not found!
There is no tenant with the tenant id or name: norules
So what I am looking for is to modify whatever routine looks at the SaasTenants table AFTER the domain resolver pulls the deal and tell it to match on something like:
Regex.Replace(Tenant.Name, @"\s", "");
Not a bug, per se, but I was wondering what would be the easiest way to extend the Domain Tenant Resolver functionality with custom string rules for matching on the tenant name side?
For example, I have a tenant with the name "No Rules" in the database, and I want to match on "norules.localhost", but the system keeps kicking back that it can't find a tenant with that name.
So, what I am looking to do is one of two things (whichever is easiest):
Let me know if you need any code from my side. Thus far the project is very close to the commercial startup template.