Organization single sign-on
Organization single sign-on lets every organization on the gateway bring its own identity provider. People type their work email on the login page, the gateway looks up which organization has verified that email domain, and sends them to that organization's OIDC or SAML provider. After sign-in they land in that organization with the role and teams its mappings give them. A Spanway Cloud tenant is an organization, so tenants configure this the same way. The gateway-wide SSO on the Admin UI single sign-on page keeps working unchanged and stays the fallback for everyone whose domain no organization has verified.
Organization SSO is an enterprise feature. Without a license that grants the organization_sso feature every /organization/sso route returns 403 and the login page never routes to an organization. On Spanway Cloud, single sign-on is included in plans whose quota sets sso: true, which is the enterprise tier by default. Tenants on other plans can read their setup but cannot add identity providers or SCIM tokens, and their existing providers stop accepting sign-ins.
A real-world scenario
A gateway serves two business units that run as separate organizations, each with its own Okta. The admin of the first organization wants her people to sign in with their own Okta, join her organization's default team automatically, and have members of the gateway-admins group become organization admins. She must not be able to sign anyone from the other organization in through her provider, and she must not be able to make herself a proxy admin. Organization SSO gives her exactly that, and a proxy admin never has to touch her setup.
Steps
-
In the Admin UI open Organizations, open the organization, and choose the SSO tab. Proxy admins see the tab for every organization, organization admins for their own.
-
Under Identity providers choose the add button, fill in the Display name, choose the Protocol (
oidcorsaml), and for OIDC enter the Issuer URL, Client ID, client secret and Scopes. Under the mapping fields set the Groups claim or attribute, the Default team ID, the Default organization role, and onegroup=roleorgroup=team_idper line in Role mappings and Team mappings, then save. The same through the API:curl -s -X POST http://localhost:4000/organization/sso/connection/new \-H "Authorization: Bearer $ORG_ADMIN_KEY" -H "Content-Type: application/json" \-d '{"organization_id": "org-examplecorp","display_name": "Examplecorp Okta","idp": {"protocol": "oidc", "issuer_url": "https://examplecorp.okta.com", "client_id": "0oa1", "client_secret": "..."},"mapping": {"default_team_id": "team-examplecorp", "role_mappings": {"gateway-admins": "org_admin"}}}' -
Register the redirect URL at the identity provider. For OIDC it is the same for every organization,
<PROXY_BASE_URL>/sso/org/callback. For SAML the table on the SSO tab shows each connection's ACS path, andGET /sso/org/<connection_id>/saml/metadatareturns the service provider metadata to upload. -
Under Email domains type the domain,
examplecorp.com, and choose the claim button. The table shows the TXT record to publish with a Copy button. The same through the API:curl -s -X POST http://localhost:4000/organization/sso/domain/new \-H "Authorization: Bearer $ORG_ADMIN_KEY" -H "Content-Type: application/json" \-d '{"organization_id": "org-examplecorp", "domain": "examplecorp.com"}' -
Publish the DNS record the answer names,
TXT _spanway-verification.examplecorp.comwith the valuespanway-domain-verification=<token>. Once it is live, choose the verify button on the domain's row, or call the API. A proxy admin also sees a Mark verified button that skips DNS, for example for an internal domain.curl -s -X POST http://localhost:4000/organization/sso/domain/verify \-H "Authorization: Bearer $ORG_ADMIN_KEY" -H "Content-Type: application/json" \-d '{"organization_id": "org-examplecorp", "domain": "examplecorp.com"}' -
Ask someone with an
@examplecorp.comaddress to open the login page, type their work email under Work email and continue.
Expected result
Step 2 returns the connection with its connection_id and login_path, and the SSO tab lists it with an enable switch. Step 5 returns the domain with "verified": true. In step 6 the login page calls POST /sso/org/discover with the email, gets {"kind": "org_sso", "login_path": "/sso/org/<connection_id>/login", "display_name": "Examplecorp Okta"}, and sends the person to Okta. After signing in they are a member of org-examplecorp in team-examplecorp, with org_admin if their groups include gateway-admins and internal_user otherwise. Every connection, domain and SCIM token change is written to the audit log, and so is a sign-in that adds the person to the organization or changes their organization role, as a Spanway_OrganizationMembership row changed by org_sso.
Identity providers
An organization can have several connections, each either OIDC or SAML.
| Field | Meaning |
|---|---|
display_name | Shown on the login page as the provider name. |
idp.protocol | oidc or saml. |
idp.issuer_url | OIDC only. The issuer, which must be an https URL. The gateway reads <issuer_url>/.well-known/openid-configuration and refuses a document that names a different issuer or a non-https endpoint. |
idp.client_id, idp.client_secret | OIDC only. The secret is encrypted with the gateway salt key before it is stored, is never returned by the API, and is re-encrypted by master key rotation. Leave it out of an update to keep the stored one. |
idp.scopes | OIDC only. Must include openid. Defaults to openid email profile. |
idp.idp_metadata_url or idp.idp_metadata_xml. | SAML only. Exactly one of the two. |
mapping.groups_claim | The ID token claim, or SAML attribute, that carries the user's groups. Defaults to groups. |
mapping.default_team_id | A team of this organization every user from this provider joins. |
mapping.default_role | The organization role a user gets when no role mapping matches: org_admin, internal_user or internal_user_viewer. Defaults to internal_user. |
mapping.role_mappings | {group: organization_role}. When several groups match, the strongest role wins. When this map is not empty the identity provider is authoritative and the role is rewritten on every sign-in. When it is empty the role is only set the first time a user joins. |
mapping.team_mappings | {group: team_id}. Every team must belong to the same organization, the API refuses anything else with 400. |
Each SAML connection is its own service provider. Its entity ID is <PROXY_BASE_URL>/sso/org/<connection_id>/saml/metadata and its assertion consumer URL is <PROXY_BASE_URL>/sso/org/<connection_id>/saml/acs. SAML needs the optional saml extra, the same as the gateway-wide SAML login.
Verified email domains
A connection only accepts people whose email domain the organization has verified, and a verified domain belongs to exactly one organization. This is what stops one organization's identity provider from signing in users of another organization.
Several organizations can hold a pending claim on the same domain at once, so claiming a domain you do not own blocks nobody. The first organization to verify the domain keeps it, and every other pending claim on that domain is removed at that moment. Once a domain is verified, other organizations get 409 when they try to claim it. On Spanway Cloud, claiming a domain needs a plan with single sign-on.
| Record | Value |
|---|---|
TXT _spanway-verification.<domain> | spanway-domain-verification=<token> |
When the DNS lookup itself fails, for example on a timeout, the verify call answers 503 instead of treating the domain as unverified, so try again. An organization admin cannot attest. POST /organization/sso/domain/update with {"organization_id": ..., "domain": ..., "connection_id": ...} routes a domain to one connection of the organization, and null uses the organization's first enabled connection. POST /organization/sso/domain/delete releases a claim. Subdomains are separate domains and need their own claim.
Signing in
The login page shows a work email field when at least one connection is enabled. In that case it also stops sending everyone straight to the gateway-wide SSO when auto_redirect_to_sso is on, and people whose domain no organization verified reach the gateway-wide SSO through discovery instead. POST /sso/org/discover answers with one of three shapes and depends only on the email domain, never on whether the person has an account.
kind | Meaning |
|---|---|
org_sso | Go to login_path, the organization's connection on this gateway. |
global_sso | No organization claims the domain, use the gateway-wide SSO at login_path. |
password | No SSO applies, use username and password. |
Discovery is limited to 30 lookups per minute per client address, where the client address is the one behind your load balancer when trusted_proxy_ranges lists it, see which address is checked. An OIDC sign-in uses the authorization code flow with PKCE, a state value bound to the browser by a cookie and usable once, and a nonce checked in the ID token. The ID token must be signed with an asymmetric algorithm by a key from the provider's JWKS, for this client ID and issuer. An email the provider reports as unverified is refused, and when the ID token carries no email the gateway reads it from the userinfo endpoint only if the subject matches. A SAML sign-in must answer a login request this browser started on the same connection, every assertion is accepted once, and IdP-initiated responses are refused.
After the identity is checked, the email domain must be a verified domain of the connection's organization. The gateway then looks up accounts whose email matches exactly, ignoring case. The identity provider's subject is never used to find an account, and neither is a user id or SSO id that happens to look like the email.
| Accounts with that email | Result |
|---|---|
| None. | A new account is created with a fresh random user id. |
One that is a member of this organization, with the internal_user or internal_user_viewer gateway role and no custom role. | The person signs in to that account. |
One that holds any other gateway role (proxy_admin, proxy_admin_viewer, org_admin as a gateway role), has a custom role, or is the PROXY_ADMIN_ID account. | Refused with 401. These accounts sign in through the gateway's own sign-in. |
| One that is not a member of this organization. | Refused with 401. An admin must add it to the organization first. |
| More than one. | Refused with 401. |
The person is then given the organization membership, role and teams from the connection's mappings. Organization SSO never grants a gateway-wide role such as proxy admin, and an organization admin cannot use their own identity provider to sign in to an account with more access than the organization gives. The session is the same Admin UI session the gateway-wide SSO issues, and ALLOWED_EMAIL_DOMAINS and ui_access_mode still apply. Every outbound call to an identity provider goes through the gateway's SSRF guard, because an organization admin chooses the issuer URL.
Organization-scoped SCIM
Under SCIM provisioning on the SSO tab, the create button mints a SCIM bearer token for the organization and shows it once with Copy SCIM token. The same through the API:
curl -s -X POST http://localhost:4000/organization/sso/scim_token/new \
-H "Authorization: Bearer $ORG_ADMIN_KEY" -H "Content-Type: application/json" \
-d '{"organization_id": "org-examplecorp", "key_alias": "Examplecorp Okta SCIM"}'
The token is a virtual key restricted to /scim/* that carries the organization id, and the SCIM endpoints confine it to that organization.
| Operation | With an organization token |
|---|---|
| List and get users. | Only members of the organization. Anyone else is 404. |
| Create user. | The user joins the organization as internal_user. The email must be on a verified domain of the organization, otherwise 400. An email that already belongs to another account the organization does not own is 409. |
| Identifiers. | userName and externalId may not name another account by user id, SSO id or email (409), and a value that contains @ must be the user's own email (400). |
Change user (PUT, PATCH). | Only accounts the organization owns: a member with the internal_user or internal_user_viewer gateway role, no custom role, no other organization and no team outside this organization. Any other member is 403. A new email follows the same rules as on create. |
| Delete user. | An account the organization owns is deleted. Any other member, such as a proxy admin or someone who also belongs to another organization, is only removed from this organization and its teams. |
| Groups. | Only the organization's teams. New groups become teams of the organization. Members must already exist and belong to the organization. The token never creates placeholder users for unknown members, they are 400. |
| User groups. | Group references outside the organization are 404, and memberships of other organizations' teams are left alone. |
scim_admin_group | Ignored, so a token can never grant proxy admin. |
| Placeholder repair. | 403, it needs a deployment-wide token. |
An organization-scoped token needs a license that includes organization_sso, the same feature that organization sign-in uses. If the license is renewed without it, every request with such a token gets a 403 naming the feature, so provisioning stops at the same moment as organization sign-in instead of carrying on unnoticed. In the Admin UI the organization's SSO tab then shows a license notice in place of the lists. A token without an organization keeps the deployment-wide behavior. GET /organization/sso/scim_token/list lists an organization's tokens and the Revoke button or POST /organization/sso/scim_token/delete revokes one.
Who can do what
A proxy admin manages every organization. An organization admin (org_admin membership) manages their own organization and nobody else's. A proxy admin viewer can read every organization's setup but not change it. Plain members of an organization get 403. Custom roles cannot grant these routes.
| Method | Path | Summary |
|---|---|---|
| GET | /organization/sso/connection/list | List an organization's identity provider connections |
| POST | /organization/sso/connection/new | Add an identity provider to an organization |
| POST | /organization/sso/connection/update | Change, enable or disable an identity provider connection |
| POST | /organization/sso/connection/delete | Remove an identity provider connection |
| GET | /organization/sso/domain/list | List an organization's claimed email domains |
| POST | /organization/sso/domain/new | Claim an email domain for an organization |
| POST | /organization/sso/domain/update | Route a domain to one of the organization's connections |
| POST | /organization/sso/domain/verify | Verify a claimed domain by DNS, or attest it as a proxy admin |
| POST | /organization/sso/domain/delete | Release a claimed domain |
| GET | /organization/sso/scim_token/list | List an organization's SCIM tokens |
| POST | /organization/sso/scim_token/new | Mint an organization-scoped SCIM token |
| POST | /organization/sso/scim_token/delete | Revoke an organization's SCIM token |
| POST | /sso/org/discover | Find where a person with this email signs in |
The sign-in routes themselves take no key. GET /sso/org/<connection_id>/login and GET /sso/org/callback carry the OIDC flow, and GET /sso/org/<connection_id>/saml/login, POST /sso/org/<connection_id>/saml/acs and GET /sso/org/<connection_id>/saml/metadata carry SAML.
Errors
| What you see | Why | Fix |
|---|---|---|
403 naming the organization_sso feature. | The license does not include it, or the Cloud plan has no SSO. | Ask for a license with organization_sso, or move the tenant to a plan with sso: true. |
403 on a connection or domain route. | The caller is a plain member, or an organization admin of a different organization. | Use a proxy admin key or an admin of that organization. |
400 teams ... are not in organization | default_team_id or a team mapping names a team of another organization. | Map to teams that belong to this organization. |
400 idp.client_secret is required | A new OIDC connection, or an update that switches to OIDC, has no secret. | Send idp.client_secret. On an update of an existing OIDC connection leave it out to keep the stored one. |
409 domain ... is already claimed by this organization or verified by another one | Another organization verified the domain, or you already claimed it. | Check the domain list. A verified domain can only be released by the organization that holds it. |
400 TXT record ... was not found | The DNS record is not published yet or has the wrong value. | Publish exactly the name and value from the domain row, wait for DNS to propagate, then verify again. |
503 from domain verify. | The DNS lookup itself failed. | Try again. A proxy admin can use Mark verified meanwhile. |
403 Only a proxy admin can attest domain ownership | An organization admin sent attest: true. | Verify by DNS, or ask a proxy admin. |
401 after signing in at the organization's provider. | The email domain is not verified for this organization, the account holds a gateway role, belongs to no organization or to several accounts. | See the account table above. Add the person to the organization, or have gateway-wide admins sign in through the gateway's own sign-in. |
429 Too many sign-in lookups, try again in a minute | More than 30 discovery calls in a minute from one address. | Wait a minute. Behind a load balancer set trusted_proxy_ranges, or every visitor shares one address. |
429 Too many sign-in attempts, try again in a minute | The sign-in throttle refused this address. | Wait a minute. |
429 The identity provider is being contacted too often, try again soon | The gateway limits how often it fetches one provider's discovery document. | Wait and retry. |
404 This sign-in link is not available | The connection is disabled, deleted or not licensed. | Turn the connection back on, or use the gateway's own sign-in. |
404 connection_id=<id> not found or 404 domain=<domain> is not claimed by organization <id> | The id or domain is wrong. | Check the SSO tab of the organization. |
400 connection_id=<id> is not in organization <id> | A domain was pointed at a connection of another organization. | Pick one of this organization's connections. |
500 Set a master key to use the Admin UI | The gateway has no master key, so it cannot start a session. | Set SPANWAY_MASTER_KEY. |
502 during sign-in. | The identity provider's discovery document or JWKS could not be fetched, or names a different issuer. | Check the issuer URL is https and returns a document whose issuer matches it. |
502 Could not parse the identity provider metadata. The gateway log has the cause. | The SAML metadata at idp.idp_metadata_url or in idp.idp_metadata_xml is not valid SAML metadata. | Read the org sso: could not parse the IdP metadata log line and paste the metadata again. |
401 Could not process SAML response. The gateway log has the cause. or 401 SAML authentication failed. The gateway log has the cause. | The provider's SAML answer could not be read or failed validation (expired, wrong audience, sent for another connection). The reason stays in the log so it never reaches the browser. | Read the matching org sso: log line. |
500 Invalid SAML configuration. The gateway log has the cause. or 500 Invalid SAML service provider metadata. The gateway log has the cause. | The SAML settings built from the connection are not usable. | Read the org sso: SAML settings could not be loaded or org sso: SAML service provider metadata is invalid log line. |
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| WARNING | org sso: refused sign-in through <connection>: <reason> | A person was turned away after signing in at the provider. | Read the reason, then fix the account as the account table above says. |
| WARNING | org sso: team <team> is not in organization <org> | A mapped team belongs to another organization, so the person was not added to it. | Fix the team mapping on the connection. |
| WARNING | org sso: SAML response could not be processed: <reason> or org sso: SAML authentication failed: <reason> | A SAML sign-in was refused. The person only saw the fixed 401 text. | Check the provider's certificate, clock and reply address. |
| WARNING | org sso: could not parse the IdP metadata: <reason> | The connection's SAML metadata is broken. | Paste valid metadata on the connection. |
| ERROR | org sso: SAML settings could not be loaded: <reason> or org sso: SAML service provider metadata is invalid: <reason> | The SAML settings for a connection cannot be used. | Fix the connection's metadata. |
Related
- Admin UI single sign-on is the gateway-wide fallback.
- SCIM provisioning describes the endpoints an organization token calls.
- Team membership from SSO is the gateway-wide version of group to team mapping.
- Spanway Cloud for plans and tenants.
- Master key rotation re-encrypts stored client secrets.
- Audit logs record every change.