Prompt
How do I support multi-tenant customer identity for different brands?
Latest observation
To support multi-tenant customer identity for different brands, the main goal is to let one identity platform serve many brands while keeping each brand’s users, data, and login experience properly separated.
1) Decide your tenancy model
There are a few common patterns:
A. One tenant per brand
- Each brand gets its own isolated identity tenant.
- Best when brands need strong separation, different policies, or different auth providers.
- Pros: simple isolation, less chance of cross-brand leakage.
- Cons: more operational overhead, duplicate config.
B. Single shared tenant with brand-aware identity
- One identity system serves all brands.
- Users may belong to one or more brands.
- Brand is stored as a first-class attribute, such as
brand_id,organization_id, ortenant_id. - Pros: easier to manage centrally, supports shared users.
- Cons: requires very careful authorization and data partitioning.
C. Hybrid
- Shared identity core, but brand-specific realms/apps/policies.
- Often the best option when some brands need isolation but others can share infrastructure.
2) Model identity around tenant context
Every request should know which brand/tenant it belongs to.
Common ways to resolve tenant:
- Subdomain:
brandA.example.com - Custom domain:
login.brandA.com - Path-based:
example.com/brandA - App/client configuration: the frontend knows the tenant ID
Once you resolve the tenant, use it everywhere:
- login screen branding
- IdP selection
- MFA policy
- claims issued in tokens
- profile and permissions lookup
- audit logs
3) Use tenant-scoped identifiers and claims
Avoid relying only on email as the unique identity across all brands.
Instead, include:
tenant_idbrand_iduser_id- optional
external_subject_id
In tokens/JWTs, add claims like:
tidortenant_idbrandrolesgroupsauth_methods
This prevents ambiguity when the same person exists in multiple brands.
4) Separate authentication from authorization
A user being authenticated does not mean they belong to a brand.
You need:
- Authentication: “Who are you?”
- Authorization: “What brand/tenant can you access, and what can you do there?”
Typical flow:
- Resolve brand/tenant.
- Authenticate user.
- Check user membership in that tenant.
- Issue token scoped to that tenant.
- Enforce tenant checks on every API call.
5) Support brand-specific login and policies
Each brand may want different:
- logo, colors, copy
- password rules
- MFA requirements
- SSO/SAML/OIDC connection
- email templates
- allowed domains
- account recovery rules
Keep these in a tenant config store:
tenant_id- branding settings
- auth policy settings
- IdP settings
- email/SMS templates
- session settings
6) Design for multiple identity providers
In B2B or multi-brand systems, one brand may use:
- local username/password
- enterprise SAML
- OIDC from Azure AD / Okta / Google Workspace
Store IdP connections per tenant:
tenant_ididp_type- issuer/client metadata
- domain hints
- routing rules
Use email domain discovery if helpful:
@company.comroutes to that brand’s IdP- fallback to local auth
7) Enforce tenant isolation in data storage
Identity data must be partitioned by tenant.
At minimum:
- every user record has
tenant_id - every role/group/membership record has
tenant_id - every lookup is filtered by tenant
- unique constraints are scoped by tenant
Example:
UNIQUE(tenant_id, email)UNIQUE(tenant_id, external_id)
For stronger isolation, consider:
- separate schemas per tenant
- separate databases per tenant
- encrypted tenant-specific secrets/keys
8) Handle users in multiple brands carefully
Some users may belong to multiple brands.
Options:
- separate accounts per tenant
- one global account with per-tenant memberships
- linked identities with shared profile data
Best practice:
- have a global subject ID for the person
- store memberships per tenant
- issue tokens scoped to exactly one tenant context at a time
This avoids accidental privilege crossover.
9) Make session and token scope tenant-aware
Sessions should be tied to a specific tenant context.
For example:
- user logs into Brand A
- session/token is only valid for Brand A
- switching to Brand B requires explicit tenant selection or re-authentication
This helps prevent:
- wrong-brand access
- mixed brand UI state
- authorization mistakes
10) Plan for admin and support access
Admins and support staff often need cross-tenant access.
Use separate roles:
- tenant admin
- brand admin
- support agent
- super admin
Require:
- elevated permissions
- audit logging
- optional step-up authentication
- just-in-time access where possible
11) Audit everything by tenant
Log:
- login events
- MFA challenges
- role changes
- IdP changes
- user creation/deletion
- tenant config changes
Include:
tenant_id- actor
- target user
- timestamp
- source IP
- auth method
This is critical for incident response and compliance.
12) Recommended implementation pattern
A practical architecture is:
- Tenant Resolver: determines brand from domain/subdomain/path
- Brand Config Service: returns branding and auth settings
- Identity Service: handles authentication and user profiles
- Membership Service: maps users to tenants/roles
- Policy Engine: evaluates access based on tenant and role
- Token Service: issues tenant-scoped tokens
- Audit Service: records all events
13) Key pitfalls to avoid
- Using email as a global unique identifier across all tenants
- Forgetting tenant checks on backend APIs
- Letting a session span multiple tenants without explicit switching
- Hardcoding branding or auth policies
- Sharing secrets or IdP configs across tenants without isolation
- Storing tenant data without
tenant_idin every relevant table
14) A simple rule of thumb
If a user, token, record, or permission can be interpreted without tenant context, your design is probably too risky.
If you want, I can also give you:
- a reference data model for multi-tenant identity,
- a JWT claim design, or
- an example using Auth0 / Cognito / Azure AD B2C / Keycloak.