Auth0 Multi-Tenant Architecture — Managing Multiple Organizations
In this tutorial, you will learn about Auth0 Multi. We cover key concepts, practical examples, and best practices to help you master this topic.
Auth0 multi-tenant architecture supports applications that serve multiple organizations (tenants), with isolated user directories, organization-specific connections, and role-based access per organization.
What You'll Learn
By the end of this lesson you will understand multi-tenant Design Patterns, configure Auth0's Organizations feature, manage organization members and connections, and implement tenant-specific authorization.
Why It Matters
B2B applications need to isolate each customer organization's data and users. Auth0's Organizations feature provides built-in multi-tenancy without building custom tenant management infrastructure.
Real-World Use
DodaZIP for Business uses Auth0 Organizations. Each company gets an organization with its own SSO configuration, user directory, and role assignments. Users see only data belonging to their organization.
flowchart LR
subgraph "Auth0 Single Tenant"
Org1[Organization: Acme Corp]
Org2[Organization: Globex Inc]
end
Org1 --> U1[Acme Users]
Org1 --> C1[Acme Connections]
Org2 --> U2[Globex Users]
Org2 --> C2[Globex Connections]
style Org1 fill:#eb5424,color:#fff
style Org2 fill:#eb5424,color:#fff
Organizations Feature
Auth0's Organizations provide native multi-tenant support.
# organizations_intro.py
# Auth0 Organizations overview
def organizations_feature():
features = {
"Organization Entity": "Represent each customer as an organization",
"Organization Members": "Users associated with specific organizations",
"Organization Connections": "Per-organization SSO and social connections",
"Organization Roles": "Roles scoped to a specific organization",
"Branding": "Per-organization branding for Universal Login",
"Metadata": "Custom key-value data per organization",
"Invitations": "Email invitations for organization members",
}
print("Auth0 Organizations Feature:")
for feature, desc in features.items():
print(f" {feature:30s} | {desc}")
organizations_feature()
Creating Organizations
Create and manage organizations programmatically.
# create_organizations.py
# Creating and managing organizations
import requests
import os
def create_organization():
domain = os.getenv("AUTH0_DOMAIN", "your-tenant.us.auth0.com")
mgmt_token = os.getenv("AUTH0_MGMT_TOKEN", "your-mgmt-token")
headers = {
"Authorization": f"Bearer {mgmt_token}",
"Content-Type": "application/json",
}
# Create an organization
response = requests.post(
f"https://{domain}/api/v2/organizations",
headers=headers,
json={
"name": "acme-corp",
"display_name": "Acme Corporation",
"branding": {
"logo_url": "https://acme.com/logo.png",
"colors": {"primary": "#2563eb"}
},
"metadata": {
"plan": "enterprise",
"seats": 100
}
}
)
if response.status_code == 201:
org = response.json()
print(f"Organization created: {org['id']}")
print(f"Name: {org['display_name']}")
print(f"Status: {org.get('status', 'active')}")
return org
else:
print(f"Failed: {response.text}")
return None
create_organization()
Organization Connections
Configure per-organization authentication connections.
# org_connections.py
# Per-organization connections
def org_connections_setup():
print("Organization Connections:")
print()
print("Each organization can have its own:")
print(" - SAML connection (corporate SSO)")
print(" - Azure AD connection")
print(" - Google Workspace connection")
print(" - Social connections (optional)")
print(" - Database connection (org-specific users)")
print()
print("How it works:")
print(" 1. Create connection in Auth0 (e.g., Acme SAML)")
print(" 2. Enable the connection for the organization")
print(" 3. Users from that org see only their SSO option")
print(" 4. Other orgs do not see this connection")
print()
print("API Endpoint:")
print(" POST /api/v2/organizations/{org_id}/connections")
print(" Body: { connection_id: 'con_xxx', assign_membership_on_login: true }")
org_connections_setup()
Organization Roles
Assign roles that are scoped to specific organizations.
# org_roles.py
# Organization-scoped roles
def org_role_assignment():
print("Organization Role Assignment:")
print()
print("Per-organization roles:")
print(" Member: Can view and edit own data")
print(" Admin: Can manage organization settings")
print(" Billing: Can view billing information")
print()
print("Adding members with roles:")
print(" POST /api/v2/organizations/{org_id}/members")
print(' Body: {"members": ["auth0|user123"], "roles": ["rol_member", "rol_admin"]}')
print()
print("The token includes:")
print(" - org_id: Which organization")
print(" - org_roles: Roles within that org")
print(" - permissions: Scoped to the organization")
org_role_assignment()
Common Mistakes
Not using the org_id in RLS-like policies: When accessing data, always check the user's org_id from the token. Forgetting this leaks data across organizations.
Sharing connections across organizations: Each organization should have its own connections. Sharing connections leaks authentication methods between orgs.
Not scoping roles to organizations: Roles should be assigned per-organization. A user might be admin in one org and member in another.
Using a single tenant for everything: For true multi-tenancy, consider using one Auth0 tenant per organization for maximum isolation.
Ignoring organization branding: Each organization should see its own branding during login, not the default auth0 tenant branding.
Practice Questions
What is Auth0's Organizations feature? Native multi-tenant support with per-organization users, connections, roles, and branding.
How do you assign a user to an organization? Use the Management API: POST /api/v2/organizations/{org_id}/members.
How do you restrict connections to specific organizations? Enable the connection for the specific organization in the Dashboard or via API.
How do you get the organization ID from a token? The organization ID is included in the access token as the
org_idclaim.Challenge: Design a multi-tenant architecture for a B2B application with organizations, per-org SSO, org-scoped roles, and data isolation.
FAQ
Mini Project
Create a multi-tenant configuration for a B2B file sharing application with organization creation, per-org SSO, role assignment, and data isolation enforcement.
def multi_tenant_plan():
print("Multi-Tenant Architecture Plan:")
print()
print("Organization setup:")
print(" - Create org for each customer company")
print(" - Configure per-org SAML or Google Workspace SSO")
print(" - Assign org-specific branding")
print()
print("User management:")
print(" - Invite users to specific orgs")
print(" - Assign org-scoped roles (admin, member, viewer)")
print(" - Users can belong to multiple orgs")
print()
print("Data isolation:")
print(" - Extract org_id from token on each request")
print(" - Filter database queries by org_id")
print(" - Never expose data from other organizations")
multi_tenant_plan()
What's Next
Next: Machine to Machine for API authentication.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro