Base solution for your next web application
Open Closed

DefaultExternalAuthenticationSource - How to change the Tenant? #9046


User avatar
0
acmeware created

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)
  • User Avatar
    0
    ismcagdas created
    Support Team

    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).

  • User Avatar
    0
    acmeware created

    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.

  • User Avatar
    0
    musa.demir created

    AbpClaimTypes.TenantId = "135";

    That is not what you should do. You should change user's claims named AbpClaimTypes.TenantId to value you want.

  • User Avatar
    0
    acmeware created

    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!"

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @Rich

    We can continue via email to solve yor problem faster.

    Thanks,

  • User Avatar
    0
    musa.demir created

    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)