Base solution for your next web application
Open Closed

How to detect/set the tenant of current user from the login page without using the tenant selection in UI or subdomain? #10168


User avatar
0
connectedpeople created

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version?
  • 10.2.0 (ASP.NET CORE & Angular (.Net 5))
  • What is your product type (Angular or MVC)?
  • Angular
  • What is product framework type (.net framework or .net core)?
  • ASP.NET CORE

Requirement

We would like to identify user tenant by user name in our multi-tenant setup. We don't want to use subdomain or even we don't want to give user option to select tenant. User should simply enter his username and password and based on unique username we should be able to identify tenant of user.

  1. What changes will we required to achieve this?
  2. At which other places we will have to update code/settings apart from login?

5 Answer(s)
  • User Avatar
    0
    echonos created

    you can follow this docs Sign In Without Specifying Tenant

  • User Avatar
    0
    connectedpeople created

    Thank you @echonos for your response, after following steps in above link, I am able to login into app, but now I am not able to use OpenId Connect authenticaiton for tenants I used earlier to do login using Azure AD. How I can allow tenants to use their Azure AD for login after disabling tenant selection?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @connectedpeople

    You can't use it without changing the implementation. External authentication providers must know the TenantId. So, you may ask users to enter their email address or username to detect the tenancy first on the login page. Then, you can set the TenantId to local cookie. After that, rest of the functioanlity should work.

  • User Avatar
    0
    connectedpeople created

    I have started changing impelmentation, but when I try to get user by email or username to determine tenant, it is not returning users. var user = await _userManager.FindByNameOrEmailAsync(userNameOrEmail); Seems above method works after setting tenant only. Could you please suggest which method/manager/service I can use to get based on username or service before identifying tenant?

  • User Avatar
    0
    connectedpeople created

    I was able to retrieve TenantId of user using return await _userManager.TryGetTenantIdOfUser(userNameOrEmail);