We have a custom API implementation so without packages of ABP. We created the clientcredentials and we can get data. But on the API the TenantId is not filled so the filtering is not correct now. What should we add to the request to fill the TenantId in the filtering?
I can add it as request parameter and set the tenantId with CurrentTenant.Change(), but there must be a better way. I also tried to add the TenantId as Claim in the Client settings, but that didn't work.
13 Answer(s)
-
0
hi rick
Can you share some code or more details?
-
0
hi rick
Can you share some code or more details?
We generated the client from the REST API by swagger. This is a C#.NET client of the gateway in the Microservice solution.
This code will not help to solve this. I have to know how we can set the TenantId on the client so it will automaticly filter in the API. Of can we add a setting in the client credential section in the portal?
We can do a Teams call so I can share my screen and you can help me?!
-
0
hi
There are many ways to set the requested tenant. Please note that
CurrentUserTenantResolveContributor
should always be the first contributor for the security.https://docs.abp.io/en/abp/latest/Multi-Tenancy#default-tenant-resolvers
-
0
I was just trying to get that TenantId in our ProductService. We are running on a NGINX server so I want to try another key then “__tenantId”.
Our product service solution looks like this (Microservice):
- In the IBP.ProductService.HttpAPI I added this in the ‘ProductServiceHttpApiModule’:
- I also added the CustomTenantResolver:
- When I call the API, I got this error:
- I filled the tenantId in the querystring and in the requestHeader, but both are not used/found. See data:
Questions
-
0
Did you changed the
TenantKey
?services.Configure<AbpAspNetCoreMultiTenancyOptions>(options => { options.TenantKey = "__tenantId"; });
-
0
-
0
hi
You can try to add it in HttpApi.Host.
-
0
-
0
hi
Can you check the logs to see the tenant name or id that not found?
-
0
Can we do a Teams call to check this together instead of these tickets? Please send me an email to get in touch.
I shared my logging above and there is no other logging about tenantId or name.
-
0
Hi rick,
please keep the conversation here.
-
0
Hi rick,
please keep the conversation here.
That's okay for me but my problem is not getting solved. Most of the times it helps to share a screen :).
-
0
Hi,
ABP Applications uses a Middlewre to determine the tenant.
This middleware uses different contributor for trying to find tenant id by given order. When it finds a tenant id, the rest of contributors won't be executed.
CurrentUserTenantResolveContributor
> This should always be the first contributor for the security.QueryStringTenantResolveContributor
FormTenantResolveContributor
RouteTenantResolveContributor
HeaderTenantResolveContributor
CookieTenantResolveContributor
If the
CurrentUserTenantResolveContributor
returns the tenantId, then theQueryStringTenantResolveContributor
will not be executed.This contributors are checkin the parameter that defined in the
AbpAspNetCoreMultiTenancyOptions
for the tenant id.You can change it by configuring it as @maliming defined before.
services.Configure<AbpAspNetCoreMultiTenancyOptions>(options => { options.TenantKey = "MyTenantKey"; });
The whole tenant resolving works as defined in the documentation https://docs.abp.io/en/abp/latest/Multi-Tenancy#default-tenant-resolvers
How you achieve your problem;
- You may change the order of resolvers. As I understand, you want to make some changes for other tenant that the user does not related.
- You may add your custom tenant resolver. https://docs.abp.io/en/abp/latest/Multi-Tenancy#custom-tenant-resolvers
If you want to make your custom tenant resolver the first executed one, don't forget the change resolver orders.
Regards.