Prompt
How do I add enterprise SSO for B2B2C users while keeping local accounts?
Latest observation
A good way to do this is to support multiple authentication methods in one identity system:
- Local accounts for consumers or small customers who sign up with email/password
- Enterprise SSO for B2B2C users who sign in through their company IdP
- A way to link both to the same app user profile so the user experiences one account, not two
Recommended approach
1) Use an identity provider that supports multiple connections
Choose an IdP/auth platform that can handle both:
- Local database users (email/password, magic link, OTP, etc.)
- Enterprise federated login via SAML or OIDC
Examples:
- Auth0 / Okta Customer Identity
- Azure AD B2C / Entra External ID
- Cognito
- FusionAuth
- Keycloak
- Supabase Auth + external IdPs, depending on needs
2) Model identities separately from your app user
In your app database, keep a core User record and attach one or more login identities:
User= your application-level person/profileIdentity= login method(s), such as:- local password login
- Google/OIDC enterprise login
- SAML enterprise login
This lets one person authenticate with multiple methods while keeping one app profile.
Example schema:
users
- id
- name
- email
- tenant_id
- ...
user_identities
- id
- user_id
- provider_type (local, oidc, saml)
- provider_name (company-a, microsoft, okta, local-db)
- provider_subject
- email
- is_primary
- created_at
3) Support tenant-based routing for enterprise SSO
For B2B2C, users often belong to a company/tenant. Common patterns:
- Email domain detection
If user entersalice@acme.com, route them to Acme’s SSO connection. - Company selector
Ask “Which company do you sign in with?” - Tenant-specific login URL
Example:
/login/acme→ only shows Acme SSO + local fallback if allowed
Domain-based routing is easiest, but you should allow overrides because not all companies use their email domain or one domain may map to multiple IdPs.
4) Keep local accounts enabled as a fallback
Allow local login for:
- consumers
- smaller business customers without SSO
- admin/support accounts
- users whose company hasn’t enabled SSO yet
Common UX pattern:
- On the sign-in screen, show:
- “Continue with company SSO”
- “Email and password”
- “Create account”
- If the email domain matches an enterprise tenant, show SSO first, but still keep local login available if applicable.
5) Link enterprise identity to existing local accounts
This is the part that usually matters most.
If a user already has a local account and later their company enables SSO:
- On first SSO login, match by verified email
- If there is an existing local user with the same email, prompt to link accounts
- Require a secure step-up check before linking:
- existing password
- magic link to the email
- admin verification
- or already-authenticated session
This prevents account takeover by someone who can assert the same email through a federated IdP.
6) Decide your account-linking policy up front
There are a few common policies:
Safe default: explicit linking required
- Local account exists
- User signs in with enterprise SSO
- If email matches, ask them to confirm linking
- Do not auto-merge without proof
Managed enterprise policy
- For enterprise-managed tenants, allow automatic linking if:
- IdP email is verified
- domain is controlled by the tenant
- user has already been invited or exists in tenant directory
Admin-provisioned users
- Admin invites user
- User accepts invite through SSO or local account
- Identity gets bound to the tenant user record
Important security considerations
Verify email and issuer
Only trust:
iss/ issuer for OIDC- SAML signature and expected IdP metadata
- verified email claims, if available
Avoid blind auto-merge
Do not merge accounts solely because emails match unless you trust the IdP and tenant relationship is established.
Use tenant-scoped authorization
Authentication tells you who the user is. Authorization should also check:
- which tenant they belong to
- which roles they have in that tenant
- whether their SSO connection is still valid
Support account recovery paths
If a user loses access to the enterprise IdP but still has a local account, define what happens:
- fallback local login allowed?
- admin must re-enable?
- support-assisted recovery?
Typical login flow
- User enters email
- System checks if email domain belongs to an enterprise tenant
- If yes:
- show SSO option for that tenant
- optionally still show local login if the account supports it
- User authenticates via local password or enterprise IdP
- Your backend receives an auth callback/token
- Backend maps external identity to internal
User - App session created with tenant context and roles
If you use Auth0/Okta-style platforms
This is often implemented with:
- Database connection for local accounts
- SAML/OIDC enterprise connections for B2B tenants
- Organizations or tenant grouping
- Account linking or just one user profile with multiple identities
Practical recommendation
For most B2B2C products:
- Use a central auth platform that supports multiple identity providers
- Create a single internal user profile
- Store multiple linked identities
- Route enterprise users by email domain or tenant
- Require explicit linking when local and SSO identities collide
- Keep local accounts enabled as a supported path, not a special case
If you want, I can also give you:
- a sample database schema,
- a login flow diagram,
- or implementation examples for Auth0, Azure AD B2C, Keycloak, or Cognito.