> Hi team, I need help implementing a custom "A...
# ask-a-descoper
o
Hi team, I need help implementing a custom "Admin/Dev Impersonation" flow.
The Goal:
We are a B2B SaaS with multiple Tenants + SSO. I want internal "Opmed" developers to be able to log in and access any client Tenant, while client users are still seamlessly routed to their specific IdP via Home Realm Discovery (HRD).
The Problem:
I tried associating an Opmed user (Google Social) with a demo Tenant via 'Authorization' on the user details page, but the Tenant Selector component is empty for that user. It works fine for the actual client user (SSO).
It seems like the "Shared SSO domain" template only scopes the Tenant Selector to active SSO connections, ignoring manual user-tenant associations.
Does anyone have tips on how to allow an internal user to "see" and select from multiple client tenants during login?
m
@Akash Jivane can you help here ?
πŸ‘€ 1
a
Hi @Oren Pinkas The "Shared SSO Domain" flow template uses
ssoDomainsTenantsCount
to decide whether to show the tenant selector. This count is based on SSO domain matching β€” not direct user-tenant associations. Since your internal "Opmed" users log in via Google Social (not SSO), their email domain doesn't match any SSO domain configured on client tenants β†’ the count comes back 0 or 1 β†’ the Switch Tenant screen never renders (or renders empty). The good news: the Switch Tenant component itself does work off user-tenant associations β€” the problem is the flow logic gating it. Option 1 β€” Branch your flow for internal users (I would recommended this one) After collecting the email, add a condition that checks if the domain matches your internal domain (e.g.
@opmed.com
). If yes β†’ authenticate via Google Social β†’ show the Switch Tenant component directly (bypassing
ssoDomainsTenantsCount
entirely). If no β†’ continue with the normal HRD/SSO path for client users. For the Switch Tenant component to populate correctly, make sure your internal users are added to each client tenant via the Management API (the Authorization tab on the user profile page doesn't always behave the same way):
Copy code
POST /v1/mgmt/user/update/tenant/add
{ "loginId": "<mailto:dev@opmed.com|dev@opmed.com>", "tenantId": "<client-tenant-id>" }
Or with the SDK:
descopeClient.management.user.addTenant(loginId, tenantId)
Option 2 β€” Pre-set tenant via flow parameter Build a lightweight internal portal where devs pick a client tenant, then launch the Descope flow with the
tenant
parameter pre-set. This skips HRD completely and is clean for a dedicated impersonation/support tool. Docs: https://docs.descope.com/auth-methods/sso/with-flows#tenant-flow-parameter Option 3 β€” Select Active Tenant post-auth Let the dev authenticate via Google Social (no tenant context), then call
POST /v1/auth/tenant/select
from your backend to switch their active tenant to any client tenant on demand. Most flexible for a fully programmatic impersonation flow. Let me know if these options helps you to resolve the issue.
o
Thank you these options look promising, i'll try and get back to you!
a
Sure!
o
@Akash Jivane, thanks for the suggestions! Quick update on my testing: β€’ *Option 3 works great*β€”this is what I’ll move forward with for now. β€’ Option 1 is still hitting a wall. Even after adding the tenant via the Management API (instead of the UI), the tenant selector remains empty for my Opmed user. I’m curious why the selector isn't picking up that association. Is there a specific configuration or flag I should validate to ensure the component "sees" manually associated tenants? I'd love to dig into this further when you have a moment, but Option 3 keeps me moving. Thanks!
a
@Oren Pinkas Glad Option 3 is keeping you moving! On Option 1 β€” the empty selector is almost certainly a flow ordering issue. The Switch Tenant component reads tenant associations from the authenticated user's session, so it needs to be placed after the Google Social authentication step completes, not before. A common mistake is showing the selector screen earlier in the flow (e.g. right after email collection), where the user identity hasn't been resolved yet β€” so there's no user context to pull tenant associations from. The correct flow order for the internal-user branch: 1. Collect email β†’ condition checks for
@opmed.com
domain 2. Authenticate via Google Social (OAuth step completes here) 3. Then show the screen with the Switch Tenant component Once step 2 completes, Descope has a resolved user session and the component will correctly read all associated tenants from their profile β€” including those added via the Management API. A quick way to verify the association is working before fixing the flow: after calling
addTenant
, load the user via the API and confirm the
userTenants
array includes the expected tenant IDs:
Copy code
GET /v1/mgmt/user?loginId=dev@opmed.com
If the tenants appear in that response, the association is correct and the flow ordering is the culprit. Let me know what you find!
o
@Akash Jivane I see! now it works perfectly, thank you!
πŸ™Œ 1
a
Perfect!