Prompt
We need enterprise login for a SaaS app without breaking current users. What architecture would you recommend for SSO, provisioning, deprovisioning, and role mapping, and what are the common pitfalls to avoid?
Latest observation
A good enterprise-login design for a SaaS app is usually “local auth + federated enterprise identity + separate app authorization”. That lets you add SSO for enterprise customers without disrupting existing password users.
Recommended architecture
1) Keep your current login, add an identity abstraction layer
Don’t replace your existing auth system. Put an auth broker / identity layer in front of your app that can handle:
- Local username/password
- SSO via OIDC (preferred)
- SAML 2.0 for enterprise compatibility
- Optional social login if you already support it
Your app should treat all login methods as producing the same internal concept:
- User
- Organization / tenant
- Identity connection
- Roles / permissions
This allows gradual migration and avoids breaking current users.
2) Use OIDC as the default enterprise protocol, support SAML too
Recommended order:
- OIDC for new enterprise integrations
- SAML if you need compatibility with older IdPs
Why:
- OIDC is simpler, more modern, easier to debug
- SAML is still common in enterprise procurement
Implementation pattern:
- Each tenant can have one or more IdP connections
- Store configuration per tenant:
- protocol
- issuer/entity ID
- client ID / metadata URL
- certificate/public keys
- allowed domains
- claim mapping rules
- On login, route by:
- email domain discovery
- tenant-specific login URL
- explicit “Sign in with SSO” option
3) Separate authentication from authorization
SSO proves identity; it should not be your only source of authorization logic.
Use:
- Identity = who the user is
- Membership = which tenant/org they belong to
- Role/entitlement = what they can do
A common internal model:
usersorganizationsmemberships(user_id,org_id,status)identity_links(user_id,provider,provider_subject)rolesmembership_rolesorentitlements
This prevents IdP changes from directly breaking permissions.
4) Provisioning: support both JIT and SCIM
Use two provisioning modes:
A. Just-in-time (JIT) provisioning
Create the user on first successful SSO login if they don’t exist yet.
Good for:
- quick onboarding
- smaller enterprise customers
- initial rollout
JIT should:
- verify email/domain
- attach user to the correct org
- assign default role
- require admin approval if needed
B. SCIM provisioning
Use SCIM 2.0 for enterprise-grade lifecycle management:
- create users
- update profile attributes
- disable/delete users
- manage group membership
This is the standard for automated enterprise provisioning.
Best practice:
- treat SCIM as the source of truth for lifecycle status in enterprise tenants
- still support JIT as a fallback or for early adoption
5) Deprovisioning: disable access immediately, don’t delete immediately
When a user is removed from the IdP or deactivated in SCIM:
- Disable access immediately
- Invalidate sessions/tokens
- Preserve audit history and data ownership
- Optionally schedule deletion later, based on tenant policy
Recommended states:
activesuspended/disabledpending_deletiondeletedor soft-deleted
Important:
- Never rely only on login-time checks for deprovisioning
- Re-check status on session refresh or token exchange
- Support webhook or SCIM-driven revocation to cut off access quickly
If a user owns content:
- transfer ownership to a manager/admin
- or lock content until reassigned
6) Role mapping: map groups/claims to app roles, but keep it configurable
Do not hardcode “group X = admin” globally.
Instead:
- allow tenant-specific role mappings
- map IdP groups/roles/claims to your internal roles
- maintain a fallback default role
Example:
- IdP group
SaaS-Admins→ internal roleOrgAdmin - IdP group
SaaS-Users→ internal roleMember - IdP group
SaaS-Billing→ internal roleBillingAdmin
Design tips:
- support mapping from:
- SAML attributes
- OIDC claims
- SCIM groups
- store mappings per tenant
- resolve roles at login/provisioning time, but also support periodic sync
Be careful:
- If you use IdP groups as the source of truth, group sync becomes mission-critical
- If you use local roles as source of truth, SSO can’t fully manage access
- A good compromise: external groups determine coarse roles; local app handles fine-grained permissions
Recommended end-to-end flow
Login flow
- User enters email or clicks SSO
- App determines tenant via domain or explicit org selection
- Redirect to IdP via OIDC/SAML
- IdP authenticates user
- App validates assertion/token
- Find or create local user
- Link identity to user
- Check membership and status
- Apply role mappings
- Issue app session
Provisioning flow
- JIT: create/update on login
- SCIM: create/update/deactivate outside login
Deprovisioning flow
- SCIM deactivates user or removes from group
- App disables account immediately
- Sessions revoked
- Optional data retention workflow triggered
Common pitfalls to avoid
1) Making SSO all-or-nothing
If you force everyone onto SSO immediately, you’ll break existing customers.
Avoid by:
- supporting both local login and SSO
- enabling SSO per tenant
- migrating tenant-by-tenant
2) Not separating identity from authorization
If “logged in via IdP” automatically means “has full access,” you’ll end up with security and tenancy bugs.
Avoid by:
- always checking org membership and app role separately
- never granting access based only on email domain or successful authentication
3) Using email as the primary identity key
Email changes, can be reassigned, and may differ across IdPs.
Instead:
- use stable provider identifiers:
- OIDC
sub - SAML NameID plus issuer
- SCIM externalId / IdP user ID
- OIDC
Email should be an attribute, not the unique identity key.
4) Weak tenant discovery
If you guess the tenant from email domain without validation, you can route users incorrectly.
Avoid by:
- using explicit tenant login links for enterprises
- validating domain mapping carefully
- handling edge cases like subsidiaries, aliases, and shared domains
5) Not handling account linking safely
A user may already have a local account and later start SSO.
Avoid by:
- linking only after verified identity proof
- requiring control of the same email/domain or admin approval
- preventing account takeover through unverified auto-linking
6) Assuming group claims are always present and accurate
Group/role claims can be too large, delayed, truncated, or omitted.
Avoid by:
- supporting SCIM group sync as a fallback/primary for complex orgs
- defining default roles if claims are missing
- limiting the number of groups you depend on for authorization
7) Breaking existing sessions during rollout
Changes to auth flows can invalidate sessions unexpectedly.
Avoid by:
- versioning auth/session logic carefully
- introducing enterprise auth as an additive path
- testing token expiration and refresh behavior
- allowing gradual migration
8) Failing to revoke access quickly
If deprovisioned users retain sessions, that’s a security problem.
Avoid by:
- session store with server-side revocation
- short-lived tokens
- logout/revocation endpoint support
- periodic re-auth for sensitive actions
9) Overloading SCIM with authorization logic
SCIM is for identity lifecycle, not detailed app permissions.
Avoid by:
- using SCIM for user/group lifecycle
- using your app for fine-grained permissions
- mapping groups to coarse roles only
10) Not supporting auditability
Enterprise buyers will expect audit logs.
Log:
- SSO login
- account linking
- SCIM create/update/deactivate
- role changes
- failed assertions
- admin configuration changes
11) Forgetting edge cases in tenant ownership
What happens if the only org admin is deprovisioned?
Have procedures for:
- break-glass access
- support-assisted admin recovery
- secondary admin requirement for enterprise tenants
Practical recommendation summary
If I were designing this today, I’d do:
- Auth methods: local login + OIDC SSO + SAML support
- Provisioning: JIT first, SCIM for enterprise lifecycle
- Deprovisioning: immediate disable + session revocation + soft delete
- Authorization: internal roles and permissions, with tenant-specific mapping from IdP groups/claims
- Identity keying: stable IdP subject/external ID, not email
- Tenant isolation: explicit org membership
- Rollout: opt-in per tenant, migrate gradually, keep legacy login
If you want, I can also sketch a reference data model and sequence diagrams for login/provision/deprovision flows.