Hi, I have succesfully implemented the DefaultExternalAuthenticationSource to provide the bool for TryAuthenticateAsync. However I would like to change the tenant based on data that comes back from the external source. How do I override the Tenant in TryAuthenticateAsync (or where do you suggest) so that when the user is checked it sets the correct tenant before checking the database and updating or creating the user.
My plan is to hide the tenancy selection and override the tenant based on the return values from the external source. Where is the best place to override the tenant and what code do I use to override?
I tried a number of things in these question and in github to no avail.
Thanks.
6 Answer(s)
-
0
Hi,
TenantId is retrieved here https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Runtime/Session/ClaimsAbpSession.cs#L40. You can simply write the tenantId you want to this claim (
AbpClaimTypes.TenantId
). -
0
Hi, I have tried writing to session and also claims to change the tenant.Id but am not having any luck. I assume you just set it directly like this, but that didn't work?
AbpClaimTypes.TenantId = "135";
Can you guide me further as to where this should be done and how? I was expecting it might work by doing so in TryAuthenticateAsync as you stated. If that is the right place please let me know how. We are just getting started and still learning the framework so I apologize if this seems simple.
-
0
AbpClaimTypes.TenantId = "135";
That is not what you should do. You should change user's claims named
AbpClaimTypes.TenantId
to value you want. -
0
Could you provide a hardcoded example inside AccountController.Login POST or wherever you think it should go as to how you would change the current tenant from host to the tenant ID. I have made it as far as getting logged in but there is a warning now and it logs out.
"Current user did not login to the application!"
-
0
Hi @Rich
We can continue via email to solve yor problem faster.
Thanks,
-
0
Hi @Rich
Since our system is not designed to get tenant information from external login it need some more changes. We created a new branch and did necessary changes. You can check it. https://github.com/aspnetzero/aspnet-zero-core/compare/dev...test-external-tenant
(And here is the default of AbpLoginManager https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.ZeroCore/Authorization/AbpLoginManager.cs)