Paid Feature
This is a paid feature. Email us to get a license key to start a SuperTokens subscription.
If you do not wish to pay, you can override the recipe functions of the Multitenancy recipe on the backend to save / read information from your database instead of calling the SuperTokens core.
Creating and configuring a tenant
#
Step 1: Create a tenant and enable third party login for themThe first step in setting up a multi tenant login system is to create a tenant in the SuperTokens core. Each tenant has a unique tenantId
(a string data type) mapped to that tenant's configuation. The tenantId
could be that tenant's sub domain, or a workspace URL, or anything else using which you can uniquely identify them.
The configuration mapped to each tenant contains information about which login methods are enabled for them. You can create a tenant via our backend SDK or via a cURL command to the core. This also allows you to dynamically create tenants without manual intervention:
- NodeJS
- GoLang
- Python
- cURL
TODO
import ( "github.com/supertokens/supertokens-golang/recipe/multitenancy" "github.com/supertokens/supertokens-golang/recipe/multitenancy/multitenancymodels")
func main() { tenantId := "customer1" thirdpartyEnabled := true
resp, err := multitenancy.CreateOrUpdateTenant(&tenantId, multitenancymodels.TenantConfig{ ThirdpartyEnabled: &thirdpartyEnabled, })
if err != nil { // handle error } if resp.OK.CreatedNew { // new tenant was created } else { // existing tenant's config was modified. }}
- Asyncio
- Syncio
TODO
TODO
curl --location --request PUT '/recipe/multitenancy/tenant' \--header 'api-key: ' \--header 'Content-Type: application/json' \--data-raw '{ "tenantId": "customer1", "thirdpartyEnabled": true}'
#
Step 2: Configure the third party providers for the tenantOnce you have created a tenant with third party enabled, you need to configure which third party providers to enable for the tenant. We have several in built providers, but you can also configure a custom provider.
Once again, you can add / modify this config dynamically using our backend SDK or using a cURL command.
- NodeJS
- GoLang
- Python
- cURL
TODO
import ( "github.com/supertokens/supertokens-golang/recipe/multitenancy" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels")
func main() { tenantId := "customer1"
resp, err := multitenancy.CreateOrUpdateThirdPartyConfig(tpmodels.ProviderConfig{ TenantId: &tenantId, ThirdPartyId: "active-directory", Name: "Active Directory", Clients: []tpmodels.ProviderClientConfig{ { ClientID: "...", ClientSecret: "...", AdditionalConfig: map[string]interface{}{ "directoryId": "...", }, }, }, })
if err != nil { // handle error } if resp.OK.CreatedNew { // Active Directory added to customer1 } else { // Existing active directory config overwritten for customer1 }}
- Asyncio
- Syncio
TODO
TODO
curl --location --request PUT '/recipe/multitenancy/config/thirdparty' \--header 'api-key: ' \--header 'Content-Type: application/json' \--data-raw '{ "config": { "tenantId": "customer1", "thirdPartyId": "active-directory", "name": "Active Directory", "clients": [ { "clientId": "...", "clientSecret": "...", "additionalConfig": { "directoryId": "..." } } ] }}'
- The above code snippet shows how you can add an Active directory login to your tenant. The
clientId
,clientSecret
anddirectoryId
will be provided to you by your tenant. - You can see the required information for other providers on this page.
Next steps
You have now successfully configured a new tenant in SuperTokens. The next step is to wire up the frontend SDK to show the right login UI for this tenant. The specifics of this step depend on the UX that you want to provide to your users, but we have two common UX flows documented in the next section.