Open-source SAML SSO and organizations for B2B apps
Enterprise SSO for a B2B app with Ostiary: organizations, SAML 2.0 or OIDC per customer, DNS domain checks and SCIM provisioning from Okta or Entra ID.
Sooner or later, a B2B customer asks two questions. Can our people sign in with our own identity provider? And when someone leaves, can their access disappear without us filing a ticket? Answering yes usually means organizations, single sign-on over SAML 2.0 or OpenID Connect, and SCIM provisioning.
Ostiary ships all three in the self-hosted identity provider you deploy and own. This post covers how they fit together, what the setup looks like for an Okta or Microsoft Entra ID customer, what Ostiary checks on every SAML response, and what it deliberately does not support.
Organizations: the unit your customers map to
An organization in Ostiary has members, roles and email invitations. The roles are Better Auth's defaults, owner, admin and member, with one addition: owners and admins may also manage the organization's API keys (more on those below).
Creating an organization is reserved for platform admins, and the check runs on the server, so the user interface is not the only gate. That matters in B2B: an organization is what SSO providers and SCIM connections attach to, and you want a person on your side to decide which customers get one.
Every account is also a member of the Public organization, the default workspace for individual sign-ups. Its member list, invitations, teams and member changes are for platform admins only, so ordinary users cannot browse everyone who signed up.
If your app needs to react to membership changes, Ostiary's webhooks send organization.member.added, organization.member.removed and organization.member.role_changed, signed with the Standard Webhooks headers. The webhooks post shows how to verify them.
Enterprise SSO, one provider per customer domain
A customer's identity provider can speak OpenID Connect or SAML 2.0. Platform admins register it in the admin console under SSO and attach it to the customer's organization.
Only platform admins may register providers, because a provider claims an email domain: letting any user register one would let them intercept that domain's sign-ins. For the same reason, the domain must be one plain hostname such as acme.com, and a provider only takes sign-ins once the domain is verified with a DNS TXT record (Verify domain). The customer's IT team publishes the record; until then, nothing routes to their identity provider.
For the people signing in, the flow is short: they choose Sign in with SSO on the login page, their email domain picks the provider, Ostiary sends them to their identity provider and they come back signed in.
Setting up a SAML 2.0 connection
On the SAML 2.0 tab, Ostiary shows the service provider values your customer pastes into their identity provider, with copy buttons (<id> is the provider ID):
| Value | URL |
|---|---|
| ACS URL (single sign-on URL, reply URL) | https://auth.example.com/api/auth/sso/saml2/sp/acs/<id> |
| SP entity ID (audience URI, identifier) | https://auth.example.com/api/auth/sso/saml2/sp/metadata?providerId=<id> |
| SP metadata URL | same as the entity ID |
In the other direction, you give Ostiary the identity provider in one of three ways: a metadata URL, fetched once by the server when you save (HTTPS, public addresses only, at most 100 KB and 10 seconds); pasted metadata XML; or by hand, with the IdP entity ID, its HTTP-Redirect SSO URL and its signing certificate. The metadata must describe one identity provider with an HTTP-Redirect SSO endpoint and a valid signing certificate, and must not contain a DOCTYPE. The provider list shows when each certificate expires; after a rotation, Edit takes the new metadata.
Attribute mapping. Email and display name are required; first and last name are optional. Presets fill in the attribute names for Okta, Microsoft Entra ID, Google Workspace and JumpCloud. The user ID is always the assertion's NameID, so ask the customer for a persistent identifier.
For Okta, the whole exchange fits in four steps: create a SAML 2.0 app integration; set the single sign-on URL to the ACS URL and the audience URI to the SP entity ID, with a persistent Name ID and the email as username; add the email, firstName and lastName attribute statements; assign people and paste the metadata URL from the Sign On tab into Ostiary. Entra ID, Google Workspace and JumpCloud follow the same pattern; the enterprise SSO guide has the exact menus.
What is checked on every SAML response
SAML has a long history of subtle validation bugs, so the list of checks is worth reading in full. SAML runs on Better Auth's @better-auth/sso plugin, and Ostiary adds a guard in front of the assertion consumer service. Every response must pass all of these:
- An XML signature by the identity provider's certificate. Unsigned responses are always refused, and with Require signed assertions (the default) the assertion itself must be signed.
- The audience (the SP entity ID), the bearer
Recipientand, when present, theDestinationagainst the ACS URL, plus the issuer. InResponseTomust match an AuthnRequest this server sent in the last 5 minutes, and each request can be answered once.- Each assertion ID is accepted once, so a captured response cannot be replayed.
NotBeforeandNotOnOrAfterare required, with 1 minute of clock skew.- Exactly one assertion, signed with SHA-256 or stronger (SHA-1 is refused).
- No DOCTYPE or entity declarations, and at most 256 KB.
What is not supported
Some SAML features are left out on purpose, and it is better to know before a customer asks:
- IdP-initiated sign-in. Unsolicited responses are refused. To keep the app tile in the customer's portal, point it at
https://auth.example.com/sso, the Sign in with SSO page, so the sign-in starts from Ostiary. - Signed AuthnRequests. Leave request signing off in the identity provider.
- Encrypted assertions and single logout.
SCIM: accounts that follow the customer's directory
Single sign-on handles the front door; SCIM handles arrivals and departures. Ostiary implements SCIM 2.0 (RFC 7643 and RFC 7644) per organization at /api/auth/scim/v2. In the admin console, open the organization and choose Generate token under SCIM provisioning. The token is shown once and expires after a year; Ostiary stores only an HMAC digest of it, and each token reaches its own organization only.
Okta and Entra ID can then create, update and deactivate accounts. Google Workspace only provisions to apps from its own catalog, so it cannot push to Ostiary directly; use its SSO and invite people instead. What happens to accounts is explicit:
- A new person gets an account in the organization and signs in with the organization's SSO, or sets a password with "Forgot password".
- An existing account is linked only when its email is verified and the organization has verified that email domain for SSO. Otherwise the identity provider gets a
409conflict: it cannot take over an account by naming its address. Platform admins are never linked. - Deactivating (
active: false) or deleting a person keeps the account but bans it, signs it out everywhere and revokes its OAuth tokens. Reactivating lifts that ban, but never one set by an admin.
Organization API keys
B2B customers also run scripts. Owners and admins of an organization can create API keys that the organization owns, for one of your APIs and some of its scopes. Because the key belongs to the organization, it keeps working when the member who created it leaves. There are up to 50 per organization, and deleting the organization deletes its keys.
Every SSO registration, edit, deletion and domain verification, and every SCIM token change, lands in the audit log.
Keep reading
- The same server is a full OpenID Connect provider for your own apps: see running an OpenID Connect provider on Better Auth.
- For how Ostiary compares with a hosted platform, including where a hosted service is the better choice, read the self-hosted Auth0 alternative or the comparison table.
- Ready to try it? Deploy Ostiary and register your first SSO provider from the console.