Linking Auth0 tenants allows you to manage multiple Auth0 instances as a single entity, simplifying configuration and management. This is particularly useful for organizations with multiple business units, regions, or products that require separate Auth0 instances but need unified management.
What is linking Auth0 tenants?
Linking Auth0 tenants involves setting up cross-tenant connections so that you can manage authentication and authorization across multiple Auth0 instances. This setup helps streamline operations, reduce redundancy, and improve security consistency across your organization.
Why link Auth0 tenants?
Using a single management console for multiple Auth0 tenants can significantly reduce administrative overhead. It also ensures that security policies and configurations are consistently applied across all instances, reducing the risk of misconfigurations.
How do you set up linking between Auth0 tenants?
Setting up linking between Auth0 tenants involves several steps, including creating custom rules and configuring cross-tenant connections.
Step-by-step guide to linking Auth0 tenants
Configure a Custom Database Connection
First, you need to set up a custom database connection in one of your Auth0 tenants. This connection will act as the primary source of truth for user data.
Create a custom database connection
Go to the Auth0 Dashboard, navigate to Connections > Database, and create a new custom database connection.Implement database actions
Write scripts for actions like login, signup, and change password. Here’s an example for login:function login(email, password, callback) {
// Connect to your database and validate the user
const user = findUserByEmail(email);
if (!user || !comparePassword(password, user.password)) {
return callback(new WrongUsernameOrPasswordError(email));
}
callback(null, {
user_id: user.id.toString(),
nickname: user.nickname,
email: user.email
});
}
Set Up Rules for Cross-Tenant Authentication
Next, create rules in each tenant to handle authentication requests and redirect them to the primary tenant for validation.
Create a rule to redirect authentication requests
Navigate to Rules in the Auth0 Dashboard and create a new rule. Here’s an example rule:function (user, context, callback) {
if (context.clientName === 'Secondary Tenant') {
const targetTenantDomain = 'primary-tenant.auth0.com';
const redirectUrl = `https://${targetTenantDomain}/login?connection=your-custom-db&client=${context.clientID}&redirect_uri=${encodeURIComponent(context.protocol + '://' + context.request.hostname + '/login/callback')}&state=${context.request.query.state}`;
return callback(null, user, { redirect: redirectUrl });
}
callback(null, user, context);
}
Secure Cross-Tenant Communication
Ensure that communication between tenants is secure by using HTTPS and validating tokens.
Validate tokens
In the secondary tenant, validate tokens received from the primary tenant:function (user, context, callback) {
const jwt = require('jsonwebtoken');
const jwksClient = require('jwks-rsa');
const client = jwksClient({
jwksUri: 'https://primary-tenant.auth0.com/.well-known/jwks.json'
});
function getKey(header, callback){
client.getSigningKey(header.kid, function(err, key) {
const signingKey = key.publicKey || key.rsaPublicKey;
callback(null, signingKey);
});
}
jwt.verify(user.idToken, getKey, {}, function(err, decoded) {
if (err) {
return callback(new Error('Invalid token'));
}
callback(null, user, context);
});
}
Security considerations
Ensure proper access controls
Implement strict access controls to prevent unauthorized access to tenant configurations and user data.
Encrypt sensitive data
Always encrypt sensitive data, such as passwords and tokens, both in transit and at rest.
Regularly audit configurations
Regularly audit your Auth0 tenant configurations to ensure they meet security standards and detect any anomalies.
Best practices
Use environment variables
Store configuration settings, such as client IDs and secrets, in environment variables to keep your codebase clean and secure.
Implement logging and monitoring
Enable logging and monitoring to track authentication requests and detect suspicious activities.
Keep software updated
Regularly update your Auth0 tenants and any related software to patch vulnerabilities and improve security.
Comparison of different approaches
| Approach | Pros | Cons | Use When |
|---|---|---|---|
| Custom Database Connections | Centralized user management | Complex setup | Multiple tenants with shared user base |
| Federated Identity | Single Sign-On (SSO) support | Requires external IDP | Organizations with existing IDPs |
Quick reference
📋 Quick Reference
createDatabaseConnection- Creates a new custom database connectionsetupRule- Configures a rule for cross-tenant authenticationvalidateToken- Validates JWT tokens from another tenant
Troubleshooting common issues
Error: Invalid token signature
Solution: Ensure that the JWKS URI is correct and that the token is signed with the correct key.
Error: User not found
Solution: Verify that the user exists in the primary tenant’s database and that the database connection is correctly configured.
Key takeaways
🎯 Key Takeaways
- Linking Auth0 tenants simplifies management and improves security consistency.
- Set up custom database connections and rules for cross-tenant authentication.
- Ensure proper access controls and encrypt sensitive data.
- Implement logging and monitoring for better visibility and security.
This setup saved me 3 hours last week by eliminating redundant configurations across multiple tenants. Give it a try and streamline your identity management stack today.

