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.
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 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.
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?
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?
I am still confused. I have used the feature system to enable and disable certain functionality, but I'm not sure how to accomplish what you are suggesting with it. I just want to offer my customers a way to authenticate their applications and code to consume the API endpoints generated by the framework here and to take advantage of all of the fantastic work you guys did with the data filtering
Right, I get that and can do that easy enough, but how do the tenants authenticate to the API so that the TenantId and CurrentUser stuff is populated?
ABP Framework version: v5.3.2
UI type: MVC
DB provider: MongoDB
Tiered (MVC) or Identity Server Separated (Angular): no
Steps to reproduce the issue:"
I'm not finding any real information to assist me on this one, but I can't use the ContactViewComponent for the ContactFeature in the CMSKit pro module because it doesn't appear to be instantiating the reCaptcha code and that is a required field, so every time I try to submit the contact form I get the following error:
Your request is not valid! The following errors were detected during validation. - The RecaptchaToken field is required.
In the public website module, there was a section for adding the SiteKey and SiteSecret, and I have done that:
context.Services.AddreCAPTCHAV3(o =>
{
o.SiteKey = "{redacted}";
o.SiteSecret = "{redacted}";
});
But beyond that I am not seeing any settings or documentation that suggests I do anything else. What am I missing?
We are aware of this issue, it will be fixed with the patch version soon. As a workaround, you need to override
ContactPublicController
'sSendMessageAsync
method and delete thereCAPTCHA
related code, also you need to override theContact
component'sdefault.js
and assign a value to itsRecaptchaToken
becauseRecaptchaToken
Required
attribute is added inContactCreateInput
.
I don't have the source code for that module and my license doesn't support me downloading it, can you send me the SendMessageAsync
code as it sits now so I can override?
Just wanted to confirm that I was able to implement the workaround for the time being and everything is running smoothly. Thank you for your help.