Prompt

How do I map SSO users to tenants and roles?

Technology / Identity & Access2 observationsLast seen Nov 2, 2026

Latest observation

Nov 2, 2026OpenAI APIWeb search: off

A common way to map SSO users to tenants and roles is to do it at login based on claims from your identity provider, then resolve those claims against your app’s internal authorization model.

Typical approach

1) Identify the user uniquely

Use a stable external identifier from the SSO token, such as:

  • sub (OIDC subject)
  • email if it’s guaranteed stable in your org
  • NameID in SAML

Store a local user record keyed by that identifier.


2) Map the user to a tenant

There are a few common patterns:

A. Tenant in the token

The IdP includes a claim like:

  • tenant_id
  • org_id
  • customer_id
  • groups

Then your app maps that claim directly to an internal tenant.

Example:

  • SSO claim: tenant_id = acme
  • Internal tenant record: tenant_id = 42

B. Tenant inferred from domain or email

Example:

  • alice@acme.com → Acme tenant

This is simple, but only safe if email domain ownership is strict and verified.

C. Tenant selected after login

If a user belongs to multiple tenants:

  1. Authenticate via SSO
  2. Fetch allowed tenants from your app DB
  3. Show tenant switcher
  4. Store selected tenant in session/context

This is very common in B2B SaaS.


3) Map SSO attributes/groups to app roles

Do not trust “role” names blindly unless they come from a controlled source.

Option A: Use IdP groups

Example token claim:

{
  "sub": "12345",
  "email": "alice@acme.com",
  "groups": ["acme-admin", "billing-team"]
}

Your app maps:

  • acme-admin → tenant_admin
  • billing-team → billing_user

Option B: Use explicit role claims

Example:

{
  "roles": ["admin", "editor"]
}

Then your app translates them into internal permissions.

Option C: Maintain roles locally

SSO only proves identity; your app stores role assignment per tenant:

  • user X is Admin in tenant A
  • user X is Viewer in tenant B

This is usually the most flexible and secure model.


Recommended model

Use SSO for authentication, and your app/database for authorization.

Data model example

  • User
    • id
    • external_subject
    • email
  • Tenant
    • id
    • name
  • Membership
    • user_id
    • tenant_id
    • role

On login:

  1. Verify SSO token
  2. Find or create user by external_subject
  3. Look up memberships
  4. Assign active tenant
  5. Apply role-based permissions for that tenant

Best practices

  • Prefer immutable identifiers like sub over email.
  • Don’t rely on client-side tenant selection alone; validate tenant access on the server.
  • Keep roles tenant-scoped, not global, unless you truly need global admin.
  • If using group claims, define a clear mapping layer between IdP groups and app roles.
  • Provision/deprovision users via SCIM if possible.
  • Log tenant and role resolution for auditing.

Example flow

  1. User signs in with SSO.
  2. IdP returns:
    • sub = abc123
    • email = bob@company.com
    • groups = [tenant-7-admin]
  3. App finds user abc123.
  4. App checks memberships:
    • tenant 7 → admin
    • tenant 9 → viewer
  5. If one tenant: auto-select it.
  6. If multiple tenants: prompt user to choose.
  7. Store active tenant in session and authorize requests accordingly.

If you want, I can also show:

  • a database schema for tenant/role mapping,
  • an OIDC/SAML claim mapping example, or
  • an implementation example in Node, Python, .NET, or Java.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.