Open Closed

DefaultExternalAuthenticationSource - How to change the Tenant? #9046


0
Rich 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)
  • 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).

  • 0
    Rich 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.

  • 0
    demirmusa created
    Support Team

    AbpClaimTypes.TenantId = "135";

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

  • 0
    Rich created

    Where in the app is there an example of this?

  • 0
    Rich created

    I think I see how but the user is not logged in yet during tryauthenticate. should this go in the defaultexternal...create and update?

  • 0
    Rich created

    OK I hope I am better understanding this. I don't get a claims definition back from my external provider. It gives a literal tenant id in json. How can I force the session to switch the user to the retrieved tenant and where during the external auth process?