BBackend CourseLeroy Labs
0/0
Search the course

Enterprise SSO with SAML 2.0, OIDC for companies & domain verification

How B2B SaaS lets companies log in with their own identity provider (Okta, Entra ID). SAML assertions, SP vs IdP, ACS endpoints, per-tenant relying parties and DNS TXT domain proof.

● expertSperoTek (in dev)

The concept

Business customers want their staff to sign in with the company’s identity provider (IdP): Microsoft Entra ID, Okta or Google Workspace. When someone leaves the company, IT disables them in one place and their access to your SaaS disappears with it.

Two protocols are common:

  • SAML 2.0 is XML-based, from 2005, and still dominant in enterprises.
  • OIDC is JSON/JWT-based and modern.

SAML vocabulary

  • SP (Service Provider): you (SperoTek).
  • IdP (Identity Provider): Okta, Entra ID and so on.
  • Metadata: XML exchanged once, containing entity IDs, endpoints and signing certificates.
  • Assertion: a signed XML statement such as “user jane@acme.com authenticated at 10:02, with attributes …”.
  • ACS (Assertion Consumer Service): your endpoint that receives the assertion, via a browser POST.

SP-initiated flow

1. User enters jane@acme.com -> SperoTek sees acme.com is a verified SSO domain
2. Redirect to Acme's IdP with an AuthnRequest
3. Jane logs in at Okta (with Okta's MFA)
4. Okta auto-POSTs a signed SAMLResponse to SperoTek's ACS URL
5. SperoTek validates the signature (IdP cert), audience, time window, InResponseTo, and replay
6. Map to the company member, then issue a SperoTek session

Domain verification

Before trusting “everyone at acme.com uses this IdP”, the tenant must prove they own acme.com, typically by adding a DNS TXT record:

_sperotek-verify.acme.com  TXT  "sperotek-domain-verification=8f3a..."

Otherwise, any customer could claim gmail.com and hijack logins.

In your project

SperoTek (in dev)accesscontrol: SsoConnection · SsoDomain · SsoRelyingParties · SsoSamlHandlers · NimbusOidcProvider · DohDnsTxtLookup · SsoSettingsController · SsoSignInController
  • spring-boot-starter-security-saml2, with relying parties per tenant built dynamically from SsoConnection rows (SsoRelyingParties) rather than static config.
  • OIDC connections via NimbusOidcProvider, for IdPs that prefer it.
  • Domain verification by DNS TXT, looked up over DNS-over-HTTPS (DohDnsTxtLookup), which avoids relying on the container’s DNS resolver and is easy to stub in tests.
  • The SAML ACS route is excluded from CORS, because the IdP POSTs to it as a cross-site form, and it is protected by SAML’s own signature checks instead.
  • An sso/exchange endpoint turns a completed SSO login into SperoTek’s normal session, so MFA policy, session limits and auditing stay in one place.

Alternatives

Option Notes
Build it with Spring Security SAML2 (SperoTek) No per-connection fees; complex
WorkOS, Auth0 Enterprise, Okta CIC, Cognito federation “SSO as a service”, often priced per connection
Keycloak as a broker Self-hosted; your app speaks only OIDC to Keycloak
  • SCIM. The standard API IdPs use to provision and deprovision users automatically. It is a natural next step after SSO.
  • JIT provisioning. Create the member on their first SSO login.
  • XML signature wrapping attacks. They are why you never hand-roll SAML parsing.
  • IdP-initiated SSO. The flow starts at the IdP dashboard. It is convenient but more exposed to replay, so many SPs disable it.
  • Enforce SSO. Once SSO is set up, block password logins for that domain.

Check yourself

1. In SAML, who is the SP?
2. Why must a tenant verify domain ownership via DNS TXT?