Enterprise SSO Readiness: SAML vs OIDC for B2B SaaS
The first time a client's SaaS landed a large customer, the deal nearly stalled on page three of the security questionnaire: "Does the product support SAML 2.0 single sign-on with our identity provider? Is SCIM provision
The first time a client's SaaS landed a large customer, the deal nearly stalled on page three of the security questionnaire: "Does the product support SAML 2.0 single sign-on with our identity provider? Is SCIM provisioning available?" The app had email and password login, a users table with a unique email column, and no concept of an organisation owning a login policy. We shipped SSO in about three weeks, but most of that time went into fixing the data model, not into the protocol. If the groundwork had been there, the integration itself would have taken days.
I wrote this with help from AI tools and checked the details against the SAML 2.0 core spec, OpenID Connect Core 1.0 and the docs for common identity providers (Microsoft Entra ID, Okta, Google Workspace). I am a Principal Software Engineer in Karachi with 9+ years across PHP/Laravel, Vue, Node and .NET microservices, and I build the free developer utilities at PixelValut Tools. Everything here is about configuring and validating SSO in your own application.
๐ Series Navigation โ Enterprise SSO & Identity for B2B SaaS
- Part 1 (This Post): Enterprise SSO Readiness: SAML vs OIDC for B2B SaaS
- Part 2: Validating SAML Responses: Signatures, Audience & Clock Skew
- Part 3: SCIM Provisioning & Deprovisioning That Actually Removes Access
- Part 4: Multi-Tenant Login Routing: Domain Discovery & Enforced SSO
- Part 5: Just-in-Time Provisioning & Role Mapping From IdP Groups
- Part 6: Break-Glass Accounts & SSO Audit Logs
Related earlier posts: Session Lifecycle Hardening: Rotation, Timeouts & Server-Side Revocation ยท Step-Up Authentication for Sensitive Actions
Should a B2B SaaS app support SAML or OIDC for enterprise SSO?
Direct answer: Plan for both, but build the groundwork once. Most large enterprises still default to SAML 2.0 through Entra ID or Okta, while newer customers and Google Workspace shops often prefer OIDC. Model organisations, verified domains and per-org identity connections first; then each protocol becomes a pluggable connection type rather than a rewrite.
The groundwork that matters more than the protocol
Before choosing a library, check that your app can answer three questions for any login attempt:
- Which organisation does this user belong to? Not "which email", but which tenant controls their login.
- Which identity connection should authenticate them? Password, SAML connection A, OIDC connection B.
- What is the stable identifier from the IdP? Emails change; the IdP's subject identifier usually does not.
Here is the minimal schema I add to a Laravel app before writing any SSO code:
// database/migrations/2026_11_16_000000_create_sso_tables.php
Schema::create('organizations', function (Blueprint $t) {
$t->id();
$t->string('name');
$t->boolean('sso_enforced')->default(false);
$t->timestamps();
});
Schema::create('verified_domains', function (Blueprint $t) {
$t->id();
$t->foreignId('organization_id')->constrained()->cascadeOnDelete();
$t->string('domain')->unique(); // e.g. customer.com
$t->timestamp('verified_at')->nullable(); // DNS TXT check passed
});
Schema::create('identity_connections', function (Blueprint $t) {
$t->id();
$t->foreignId('organization_id')->constrained()->cascadeOnDelete();
$t->enum('protocol', ['saml', 'oidc']);
$t->json('settings'); // entity IDs, metadata URL, client ID
$t->boolean('active')->default(false);
$t->timestamps();
});
Schema::create('user_identities', function (Blueprint $t) {
$t->id();
$t->foreignId('user_id')->constrained()->cascadeOnDelete();
$t->foreignId('identity_connection_id')->constrained()->cascadeOnDelete();
$t->string('subject'); // SAML NameID or OIDC sub
$t->unique(['identity_connection_id', 'subject']);
});
The key design choice is user_identities: you link a user to (connection, subject), never just to an email. That one table prevents the classic mistake of letting any IdP that asserts [email protected] log in as that user.
SAML vs OIDC at a glance
| Aspect | SAML 2.0 | OpenID Connect |
|---|---|---|
| Format | Signed XML assertion | Signed JWT ID token |
| Typical transport | Browser POST to your ACS URL | Authorization code flow + back-channel token call |
| Common in | Entra ID, Okta, ADFS, older enterprises | Google Workspace, Okta, Entra ID, newer stacks |
| Setup exchange | Metadata XML (entity ID, cert, SSO URL) | Issuer URL, client ID/secret, discovery document |
| Key validation | XML signature, Audience, Recipient, NotOnOrAfter, InResponseTo | Signature via JWKS, iss, aud, exp, nonce
|
| Main risk area | XML signature handling in libraries | Skipping aud/nonce checks |
| Library advice | Use a maintained library, never hand-parse XML | Use a certified OIDC client |
In practice I implement OIDC first if the first customer uses Google Workspace, and SAML first if they use Entra ID or Okta with an existing SAML app catalogue. The schema above supports both.
Validation you must not skip
Whichever protocol you use, a maintained library should do the cryptography, but you still own the configuration. For OIDC in Node with openid-client:
import * as client from 'openid-client';
const config = await client.discovery(
new URL(conn.settings.issuer), // e.g. https://login.microsoftonline.com/<tenant>/v2.0
conn.settings.clientId,
conn.settings.clientSecret,
);
// In the callback route:
const tokens = await client.authorizationCodeGrant(config, currentUrl, {
pkceCodeVerifier: session.pkceVerifier,
expectedState: session.state,
expectedNonce: session.nonce,
});
const claims = tokens.claims(); // signature, iss, aud, exp checked by the library
const subject = claims.sub; // link via user_identities, not by email alone
For SAML, the equivalent checks are: the response or assertion is signed with the certificate from that connection's metadata, the Audience matches your entity ID, the Recipient matches your ACS URL, NotOnOrAfter has not passed (allow a small clock skew of a minute or two), and InResponseTo matches a request you actually sent. Part 2 goes through each of these in detail.
Inspecting tokens and assertions while debugging
During setup with a customer's IT team, most problems are configuration mismatches: wrong audience, wrong NameID format, a missing email claim. I debug these in a test tenant, never with a real user's production token. For OIDC, paste a test ID token into a JWT decoder to compare iss, aud and claim names with what your config expects. For SAML, the browser posts a Base64-encoded SAMLResponse; decoding it with a Base64 tool shows the XML so you can check the Audience and attribute names. Decoding is for reading only: it never replaces signature validation in your code.
# Decode a SAMLResponse captured from your own test login (never production users)
pbpaste | base64 --decode | xmllint --format - | grep -E 'Audience|NameID|Attribute Name'
A rollout plan that does not break existing users
- Ship the schema and organisation model with SSO disabled for everyone.
- Add domain verification via a DNS TXT record before any connection can activate.
- Enable one connection for one pilot organisation, with password login still allowed.
- Link existing users on their first SSO login (matching verified domain + email once, then storing the subject).
- Only then turn on
sso_enforced, and keep a documented break-glass admin (Part 6).
Diagnostic checklist
- [ ] Users belong to organisations, and organisations own login policy
- [ ] Domains are verified by DNS before SSO connections can activate
- [ ] Users are linked to IdP subject identifiers, not only emails
- [ ] Each connection stores its own certificate, issuer and client settings
- [ ] SAML Audience, Recipient, NotOnOrAfter and InResponseTo are validated
- [ ] OIDC
state,nonce, PKCE,issandaudare checked - [ ] SSO can be piloted per organisation before it is enforced
- [ ] A break-glass admin path exists and is audited
FAQ
Do I need to support both SAML and OIDC from day one?
No. Build the shared groundwork, then implement whichever protocol your first enterprise customer uses. The second one is much faster with the model already in place.
Should I use a hosted identity service instead?
It is a reasonable choice if SSO is not core to your product and you want to move fast. You still need the organisation and domain model in your own app, so the groundwork here applies either way.
Can I match users by email only?
Only once, at first link, and only for a verified domain. After that, use the stored subject. Matching by email every time lets a misconfigured or hostile IdP log in as anyone with a matching address.
Is SAML more secure than OIDC?
Neither is inherently more secure. Both are safe when validated correctly with maintained libraries. SAML has a longer history of XML signature handling bugs, which is why you should never hand-roll it.
What about SCIM?
Enterprises usually ask for it right after SSO, so that removing someone in their IdP removes them from your app. Part 3 of this series covers it.
How should I handle certificate rotation?
Store more than one certificate per SAML connection and accept either during a rotation window, and prefer metadata URLs that you refresh on a schedule.
Next in this series, Part 2 walks through validating SAML responses step by step: signatures, audience, recipient and clock skew.
Follow & Connect
- Website: PixelValut Tools
- Watch on YouTube: Resume Boost AI ยท PixelValut ยท Daily AI News By Ali
- TikTok: PixelValut (@pixelvalut007)
- GitHub: Muhammad Ali Mughal (@ali111887)
- LinkedIn: Muhammad Ali Mughal
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.