# Implementing multi-tenancy with multiple-connections

**URL:** <https://community.auth0.com/t/implementing-multi-tenancy-with-multiple-connections/39516>\
**Category:** Get Help\
**Tags:** multi-tenant\
**Created:** [March 17, 2020, 10:36am UTC](https://community.auth0.com/t/implementing-multi-tenancy-with-multiple-connections/39516 "2020-03-17T10:36:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdallomRoy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adallomroy/32/19876_2.png) [@AdallomRoy](https://community.auth0.com/u/AdallomRoy)\
**Post date:** [March 17, 2020, 10:36am UTC](https://community.auth0.com/t/implementing-multi-tenancy-with-multiple-connections/39516/1 "2020-03-17T10:36:23Z")

</div>

Hi,

A question about implementing multi tenancy with the multiple connections strategy.

When a user wants to login into my product, I ask him for a tenant name (e.g. acme).  
Let’s say for simplicity that I create database connections that are named exactly like the tenant, so I go into the login flow with the database connection name acme.  
After the user has authenticated in Auth0 is will return to my app with the id\_token/access\_token - however - these do not include the name of the connection used for authentication nor the tenant name.  
How do I then know, from which tenant the user is?  
Seems like that whole flow is completely broken.

Thanks,  
Roy.

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [March 17, 2020, 4:06pm UTC](https://community.auth0.com/t/implementing-multi-tenancy-with-multiple-connections/39516/2 "2020-03-17T16:06:08Z")

</div>

Hi Roy,

You can add information to the tokens in rules.

> **[Auth0 Rules](https://auth0.com/docs/customize/rules)**
>
> Learn about Rules and how you can use them to customize and extend Auth0's capabilities.

John

---

<div class="post-metadata">

**Author:** ![mathiasconradt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mathiasconradt/32/12758_2.png) [@mathiasconradt](https://community.auth0.com/u/mathiasconradt)\
**Post date:** [March 17, 2020, 6:29pm UTC](https://community.auth0.com/t/implementing-multi-tenancy-with-multiple-connections/39516/3 "2020-03-17T18:29:44Z")

</div>

Hi @AdallomRoy,

one main question here is: can the user potentially be part of multiple tenants or not? If he can be part of multiple tenants, and you only want to give the user one account / set of credentials, for all tenants he has access to (SSO so to speak), then you can refer to one of the approaches mentioned here:

> [@Help With Multi-Tenant SPA/REST Application](http://community.auth0.com/t/help-with-multi-tenant-spa-rest-application/38893/2):
>
> There are different options to decide which organization a user wants to work on. Option A Your mentioned option 1. is a valid choice, but if you don’t like the subdomain approach, here are the others. Option B In case of a single domain, let him select the organization via input field, similar to what Slack is doing (that’s not Auth0, but just to give you an example): This would work, the effect is similar using a subdomain. You let the user preselec…

> When a user wants to login into my product, I ask him for a tenant name (e.g. acme).

Do you ask this within your application, before doing the authorization request to Auth0? Are you asking this in the form of a text input field (like in the Slack example provided in the link above?)

If so, note that you can pass this information to Auth0 as a parameter in the authorization request. Search for `upstream_param` or `extraParams` here in the forum and you’ll find examples.

---

<div class="post-metadata">

**Author:** ![AdallomRoy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adallomroy/32/19876_2.png) [@AdallomRoy](https://community.auth0.com/u/AdallomRoy)\
**Post date:** [March 18, 2020, 9:30am UTC](https://community.auth0.com/t/implementing-multi-tenancy-with-multiple-connections/39516/4 "2020-03-18T09:30:11Z")

</div>

Thanks, we ended up using different client for different tenants, each of these clients with a different connection.  
We also used rules & client metadata in order to send the tenant id in a signed manner in the JWT token.  
This seems to be working well.  
I do think that current documentation in the area of how to implement multi tenancy is lacking and is only high level without any examples - would definitely love to see that gets better.

Thanks for you answers they were very helpful!  
Roy.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 18, 2020, 12:39pm UTC](https://community.auth0.com/t/implementing-multi-tenancy-with-multiple-connections/39516/5 "2020-03-18T12:39:39Z")

</div>

Glad we were able to help!
