Open MercatoDocsSearch docsAPI reference

Enterprise

Single Sign-On (SSO)

SSO answers who the person is at sign-in. Provisioning decides when their local account exists and when it changes. Choose just-in-time creation or directory-driven SCIM before connecting a provider, since that decision changes how onboarding and offboarding work.

Open Mercato's SSO module provides enterprise-grade Single Sign-On with OIDC and SCIM 2.0 support. This page covers architecture, configuration, and operational guidance.

Supported Identity Providers

IdPOIDC LoginSCIM ProvisioningJIT ProvisioningNotes
Microsoft Entra IDYesYesYesFull OIDC + SCIM support. See Entra ID Setup Guide
ZitadelYesYesYesOIDC + SCIM via Actions/native. See Zitadel Setup Guide
Google WorkspaceYesNoYes (recommended)OIDC only, no SCIM push. See Google Workspace Setup Guide

Architecture

Authentication Flow (OIDC)

User -> Login Page -> HRD Check -> IdP Redirect -> IdP Login -> Callback -> Session
  1. Home Realm Discovery (HRD): User enters email, the system checks if the email domain matches an active SSO config
  2. Authorization Request: OIDC Authorization Code + PKCE flow initiated with encrypted state cookie
  3. IdP Authentication: User authenticates at the identity provider
  4. Callback Processing: Authorization code exchanged for tokens, ID token validated
  5. Account Linking: User matched to existing account (by email or SSO subject) or JIT-provisioned
  6. Session Creation: Auth session established, user redirected to the application

User Provisioning

Two provisioning methods are supported, mutually exclusive per SSO config:

JIT (Just-In-Time) Provisioning

SCIM 2.0 Provisioning

Mutual Exclusivity

JIT and SCIM cannot be enabled simultaneously on the same SSO config:

Configuration

Admin Setup Steps

  1. Create SSO Config: Settings -> Single Sign-On -> Create New
  2. Enter IdP Credentials: Issuer URL, Client ID, Client Secret
  3. Add Allowed Domains: Email domains that should use this SSO config
  4. Choose Provisioning: Enable JIT or configure SCIM tokens
  5. Test Connection: Verify the IdP discovery endpoint is reachable
  6. Activate: Enable the config for production use

API Endpoints

EndpointMethodDescription
/api/sso/configPOSTCreate SSO config
/api/sso/configGETList SSO configs
/api/sso/config/:idGETGet config by ID
/api/sso/config/:idPUTUpdate config
/api/sso/config/:idDELETEDelete config (must be inactive)
/api/sso/config/:id/activatePOSTActivate/deactivate config
/api/sso/config/:id/domainsPOSTAdd domain
/api/sso/config/:id/domainsDELETERemove domain
/api/sso/config/:id/testPOSTTest IdP connection
/api/sso/hrdPOSTHome Realm Discovery lookup
/api/sso/initiateGETStart SSO login flow
/api/sso/callback/oidcGETOIDC callback
/api/sso/scim/tokensPOSTCreate SCIM token
/api/sso/scim/tokensGETList SCIM tokens
/api/sso/scim/tokens/:idDELETERevoke SCIM token
/api/sso/scim/v2/UsersPOSTSCIM: Create user
/api/sso/scim/v2/UsersGETSCIM: List users
/api/sso/scim/v2/Users/:idGETSCIM: Get user
/api/sso/scim/v2/Users/:idPATCHSCIM: Update user
/api/sso/scim/v2/Users/:idDELETESCIM: Delete user

Security

OIDC Security Controls

ControlImplementation
PKCES256 with 32-byte random code verifier
State ParameterAES-256-GCM encrypted state cookie with HKDF key derivation
Nonce16-byte random nonce validated in ID token
State ComparisonTiming-safe (crypto.timingSafeEqual)
TTL5-minute state cookie lifetime
CSRFSameSite=Lax cookies + encrypted state parameter
Return URLSanitized to prevent open redirects
Outbound RequestsDiscovery and all provider endpoints reject private/reserved or mixed DNS answers, pin the validated address, disable redirects, and enforce time/size limits

Public HTTPS identity providers work without additional configuration. For a private or on-premises provider, an operator must explicitly list every trusted private endpoint origin in OM_SSO_OIDC_PRIVATE_ORIGIN_ALLOWLIST (comma-separated exact HTTPS origins, including non-default ports). Discovered JWKS, token, and user-info origins are validated independently; allowing the issuer origin does not implicitly allow a different private origin.

SCIM Security Controls

ControlImplementation
Token Formatomscim_ prefix + 32 random bytes (hex)
Storagebcrypt-hashed (cost 10), only prefix stored
One-Time DisplayRaw token returned only at creation
Timing AttackDummy bcrypt hash on zero candidates
Tenant IsolationOrganization ID derived from token, not request

Data Protection

Provisioning Methods

JIT Provisioning

When JIT is enabled on an SSO config:

  1. User authenticates via OIDC at the IdP
  2. If the user does not exist in Open Mercato, a new account is created
  3. Profile data (name, email) extracted from ID token claims
  4. User is assigned to the organization associated with the SSO config
  5. On subsequent logins, profile data is updated from the latest ID token

Warning · Limitations

SCIM 2.0 Provisioning

When SCIM is configured:

  1. IdP pushes user create/update/delete operations to the SCIM endpoint
  2. Users are pre-provisioned before their first login
  3. Profile changes in the IdP are automatically synced
  4. User deactivation in the IdP triggers deactivation + session revocation
  5. On OIDC login, the existing SCIM-provisioned account is linked (no duplicate)

Supported SCIM Operations:

Role Mapping

SSO configs support IdP group-to-application role mapping:

  1. Configure appRoleMappings on the SSO config (map IdP group names to app role names)
  2. When the IdP sends group claims in the ID token, roles are automatically assigned
  3. If no mappings are configured, role sync is skipped (user retains existing roles)

Info · Google Workspace

Google does not send group claims by default. Role mapping is not available for Google OIDC without additional configuration.

Environment Variables

VariableRequiredDescription
SSO_STATE_SECRETYes (production)32+ byte secret for state cookie encryption
APP_URL / NEXT_PUBLIC_APP_URLRecommendedBase URL for redirect URI construction
SSO_DEV_SEEDNoSet to true to seed demo SSO config in development
OM_SSO_OIDC_PRIVATE_ORIGIN_ALLOWLISTNoComma-separated exact HTTPS origins allowed to resolve to private ranges for trusted on-prem IdPs

Troubleshooting

"State mismatch – possible CSRF attack"

"No roles could be resolved from IdP groups"

User created with wrong provisioning method

SCIM requests return 401

SCIM requests return 403

HRD not detecting SSO for an email domain

IdP-Specific Setup Guides

Verify sign-in and offboarding independently

An employee who signs in through the identity provider has passed the authentication test. Also change the assignment of a separate test user and inspect the result in Open Mercato. That second check shows whether your provisioning configuration matches the lifecycle you intend.

Previous: Google Workspace Setup · Next: Zitadel Setup