For 1 request it asks to resolve AbpPermissionManagement, AbpAuditLogging on the 2nd request it Asks to resolve only AbpAuditLogging for the same page request.
I think this is because the
Permissions
are cached. So we don't need read it from db for 2nd request.So according the the code behaviour It should try to resolve connection string for ProductManagement and Intelligence. But it only tries to resolve ProductManagement.
It will only be triggered when Intelligence-related repositories are used and the
_currentTenant.Id
not be null.Your entity also need
IsMultiTenant
I am using Single database per tenant.
Hi Ma.
I was debugging the same. There is a very wierd behaviour with the MultiTenantConnectionStringResolver code.
For 1 request it asks to resolve AbpPermissionManagement, AbpAuditLogging on the 2nd request it Asks to resolve only AbpAuditLogging for the same page request.
I was trying a workaround. where I set a custom name for the tenant connection string. So when the connectionstring is required by the dbcontext it will try to resolve using the MultiTenantConnectionStringResolver.
I have two modules which work on multitenany
So according the the code behaviour It should try to resolve connection string for ProductManagement and Intelligence. But it only tries to resolve ProductManagement.
This thread also has the same issues https://support.abp.io/QA/Questions/335/Steps-to-create-Single-Deployment---Multiple-Database-Multi-Tenant-Solution
If you can connect to me remotely I can show you the debug.
Thanks
Hi Ma
Can you provide a sample code to acheive this using MultiTenantConnectionStringResolver ?
Thanks
I have checked MultiTenantConnectionStringResolver.
I'll share zoom details on email.
I have disabled AccessTokenTenantResolver and trying to access the application it still cannot determine the tenant connection string from the database.
It only happens when a connection string for a tenant is set in the database.
Can you please do a remote session and check. I have been facing this issue since i upgraded to 4.2.2
Thanks
Hi
The current tenant id is null in MultiTenantConnectionStringResolver even after the custom tenant resolver has executed also it is null when the api is executing.
I am on version 4.2.2
Do you mean the ICurrentTenant is changed? Can you confirm? Yes. It shows the proper tenant
The connection string of the tenant is not changed based on the connection string set in the database. I am using seperate database per tenant. The connection string is stored in the database for each tenant database. While running the query the connection string is not taken from the database.
E.g The Identity Server Project Has seperate connection strings for each module
"ConnectionStrings": {
"Default": "Host=xxx.xxx.xxx.xxx;Port=5432;Database=Tenant1;Username=postgres;Password=xxxxxx;",
"AbpIdentityServer": "Host=xxx.xxx.xxx.xxx;Port=5432;Database=Identity;Username=postgres;Password=xxxxxx;",
"AbpIdentity": "Host=xxx.xxx.xxx.xxx;Port=5432;Database=Identity;Username=postgres;Password=xxxxxx;",
}
and if I set a Default Connection String for the Tenant in the database (AbpTenantConnectionStrings Table) When I Try to login to this tenant the Identity Server throws errors
Npgsql.PostgresException (0x80004005): 42P01: relation "AbpUsers" does not exist
For some reason the abp tries to find the AbpUsers table in Tenant1 Database Instead of searching for it in Identity Database.
Hello
public class AccessTokenTenantResolver : HttpTenantResolveContributorBase
{
public override string Name => "AccessToken";
protected override Task<string> GetTenantIdOrNameFromHttpContextOrNullAsync(ITenantResolveContext context, HttpContext httpContext)
{
string accessCode = httpContext.Request.Headers["Authorization"];
if (!string.IsNullOrEmpty(accessCode))
{
var token = accessCode.Split(" ")[1];
var tokenHandler = new JwtSecurityTokenHandler();
var tokens = tokenHandler.ReadJwtToken(token);
var client_id = tokens.Claims.FirstOrDefault(x => x.Type == "client_id").Value;
var scopes = tokens.Claims.FirstOrDefault(x => x.Type == "scope").Value;
}
return Task.FromResult("39fb7b60-0ba6-8109-70b1-a049e5f25575");
//throw new NotImplementedException();
}
}
I have this custom tenant resolver which resolves the tenant based on the client_id from the AccessToken. The Current Tenant Information is populated properly however the connection string of the tenant is not changed based on the connection string set in the database.
@maliming Thanks. It worked.
I am not able to find AbpClaimsServiceOptions. I am using v4.2.2. Which Package should I use to configure these options?
here is the jwt token. It doesnt contain the custom claim
{
"nbf": 1618478761,
"exp": 1650014761,
"iss": "https://localhost:44374",
"aud": [
"ResellerManagementService",
"ResellerBackendGateway"
],
"client_id": "reseller-management",
"sub": "39fb4d11-7a81-1199-d025-822914236ebf",
"auth_time": 1618478759,
"idp": "local",
"preferred_username": "admin@zed.com",
"phone_number_verified": "False",
"email": "admin@zed.com",
"email_verified": "False",
"name": "admin@zed.com",
"sid": "23DAB653DBF2AE65AD44614FC6B32290",
"iat": 1618478761,
"scope": [
"openid",
"profile",
"ResellerBackendGateway",
"ResellerManagementService"
],
"amr": [
"pwd"
]
}