How to Add SSO Login to an App You Built With AI
SSO for an AI-built app means SAML or OIDC configured per customer identity provider, not another OAuth button. Here is what actually has to be built.
Adding SSO login to an app you built with AI is not the same task as bolting on a Google or GitHub button. Single sign-on for enterprise customers means your app has to trust an identity provider it did not choose, speaking a protocol it did not pick, configured differently for every customer instead of once for your whole app. That is a materially harder problem than social login, and it is usually the one standing between you and an enterprise deal. This post covers what SSO actually requires under the marketing term, how SAML and OIDC differ, and the concrete pieces you need to build before you can put an "Enterprise SSO" line on a pricing page.
SSO vs. Social Login: Why This Is a Harder Problem
If you have already added social login to your app, you registered one OAuth application with Google or GitHub, got back one client ID and secret, and pointed one redirect URI at your callback route. Every user on the planet who signs in with Google goes through the same, fixed identity provider that you configured exactly once. Enterprise SSO flips that model. Each customer organization brings its own identity provider, Okta, Microsoft Entra ID, Google Workspace, OneLogin, JumpCloud, or a homegrown ADFS setup, and your app has to become a service provider that can be configured N different ways, once per tenant, by an IT admin you will probably never talk to directly.
Concretely, that changes almost every part of the login flow:
One OAuth app becomes a table of per-tenant connections you have to store, validate, and keep in sync as certificates expire.
A fixed set of scopes and claims becomes attribute mappings that each customer's admin configures on their end, sometimes wrong.
One redirect URI becomes a callback that must first figure out which tenant sent the request before it can even validate the response.
Logout, which barely exists as a concept in social login, becomes a protocol-level feature (SAML Single Logout) that is notoriously unreliable in practice.
Trust shifts from one vendor's cert rotation (Google's, GitHub's) to hundreds of different IT departments' configurations, each with its own typos, expired certificates, and clock skew.
SAML vs. OIDC for an AI-Built App
Enterprise SSO is built on one of two protocols, and you will likely need to support both eventually. SAML (Security Assertion Markup Language) is XML-based and dates back to the early 2000s. The identity provider sends your app a signed XML assertion after the user authenticates, your app validates the signature against a certificate the IdP gave you, and pulls attributes like email and name out of the XML. SAML uses concepts that OAuth developers usually have not touched: an Entity ID, an Assertion Consumer Service (ACS) URL, IdP-initiated versus SP-initiated flows, and X.509 certificates for signing. It is clunky, but it is still the default that a lot of enterprise security teams ask for by name because it is what their compliance checklist says.
OIDC (OpenID Connect) is newer and built directly on top of OAuth 2.0, which means it reuses plumbing you likely already have from social login. Instead of an XML assertion, you get a signed JSON Web Token (the id_token) after an OAuth code exchange. Configuration is simpler too: instead of exchanging metadata files, you typically just need a discovery URL (the IdP's .well-known/openid-configuration endpoint), a client ID, and a client secret that the customer generates on their side. Azure/Entra ID, Google Workspace, and most modern IdPs support OIDC well, and it keeps gaining ground, but plenty of large enterprises still specifically mandate SAML in their vendor security questionnaires.
Practically: build OIDC first, since it reuses your existing OAuth code and covers a growing share of customers. But design your data model so SAML can slot in later, because the two protocols carry different shapes of data (XML assertions with redirect or POST bindings, versus JWTs over OAuth) and retrofitting that distinction after the fact is more painful than planning for it up front.
The Pieces You Actually Have to Build
This is the part that gets glossed over in "just add SSO" advice. A working, multi-tenant SSO implementation has several distinct moving parts, and skipping any one of them is where the real bugs live.
1. A per-tenant connection record
You need a table, something like sso_connections, keyed to an organization, storing the protocol (saml or oidc), the IdP's metadata URL or raw XML, the entity ID, the signing certificate, and for OIDC the client ID, client secret, and discovery URL. You also need somewhere to store the attribute or claim mapping, since one IdP might send the email as "email" and another as "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress".
2. Metadata exchange
For SAML this is a two-way document swap: you publish your service provider metadata (entity ID, ACS URL, certificate) for the customer's IT admin to import, and they give you their IdP metadata (SSO URL, certificate, entity ID) to import in return, usually as a URL they paste into a setup screen. For OIDC it is lighter: a discovery URL plus a client ID and secret from an OAuth app the admin registers on their side. Either way, this exchange has to happen through a UI a non-developer customer admin can actually use, not a support ticket you handle by hand.
3. Tenant-aware callback resolution
Your ACS or OIDC callback endpoint has to work out which organization sent the response before it can validate anything, typically via a state parameter or a connection ID in the path, like /sso/callback/<connection_id>. Get this wrong and you either break the login or, worse, open a path for one tenant's users to authenticate into another tenant's data.
4. Just-in-time (JIT) provisioning
The first time a user shows up through SSO, you decide whether to create their account automatically and what to trust from the claims you received. That usually means checking the verified email domain against the org's registered domain, mapping SAML attributes or OIDC claims onto your user accounts model, and deciding what happens to SSO-only accounts if a customer later turns SSO off.
5. Session and logout
OIDC logout is a straightforward redirect with an id_token_hint. SAML Single Logout (SLO) has a reputation for a reason: front-channel logout can silently fail if any one party in the chain does not respond correctly. Most real implementations quietly settle for killing the local session on logout rather than chasing true SLO, and treat that as a documented limitation rather than a bug.
6. Testing against real identity providers
Okta and Microsoft Entra ID both offer free developer tenants, and it is worth building and testing both your SAML and OIDC flows against them before a real customer's IT admin becomes your first tester. Certificate expiry, clock skew, and case-sensitive attribute names are the failures that actually show up in production, not the happy-path login you get working on day one.
Enterprise Login for a Small SaaS: Build vs. Buy
Building SAML and OIDC support from scratch is a multi-week job even for a single protocol, and every new customer's IdP tends to surface a new quirk that turns into a support ticket. That repetitiveness is exactly why dedicated SSO providers exist, offering a thin adapter that normalizes SAML and OIDC into one API and handles the metadata exchange UI for you. For a small SaaS, the honest tradeoff is between owning the whole protocol stack yourself versus paying a vendor markup, often called the "SSO tax", to skip building and maintaining it. If enterprise SSO is one feature among many rather than your product, buying that layer is usually the faster and cheaper path; if identity is close to your core product, owning it may be worth the investment.
A Practical Rollout Order
Whether you build or buy the underlying protocol handling, the rollout sequence tends to look the same for teams building an app with AI and adding enterprise features on top of it:
Ship OIDC first. It reuses your OAuth plumbing and covers a large share of modern IdPs.
Gate it behind an actual enterprise pricing tier, with a self-serve setup screen in your admin dashboard where an org owner can paste in their IdP metadata without opening a ticket.
Add SAML once a real customer's security team asks for it by name, not before, since it is the more expensive protocol to maintain.
Build a "test connection" button so the customer's IT admin can verify their configuration before flipping SSO on for their whole company.
Log every change to a connection's configuration, since a misconfigured or maliciously altered SSO setup is a direct path to account takeover.
A lot of the boilerplate for SAML XML parsing or OIDC token validation can be scaffolded quickly with AI coding tools, but the tenant data model, the callback resolution logic, and the provisioning rules above are exactly the kind of decisions that need a human thinking through the edge cases before you ship them.
FAQ
Do I need SAML if I already support OIDC?
Not always, but often enough that you should plan for it. Some enterprise security teams specifically require SAML as a matter of vendor policy, regardless of whether OIDC would technically work just as well. If enterprise deals are the goal, expect to support both eventually.
Can Google or GitHub OAuth count as SSO for enterprise customers?
No. That is social login: a single, fixed identity provider that only Google or GitHub controls. Enterprise SSO means letting each customer's own identity provider, whichever one their IT department already runs, authenticate their users into your app.
What is JIT provisioning in SSO?
Just-in-time provisioning means creating or updating a user's account automatically the first time they authenticate through SSO, based on trusted claims like email, name, and group membership sent by the identity provider, rather than requiring a separate manual signup step.
Does Single Logout actually matter for a small SaaS?
Rarely at first. True SAML Single Logout is unreliable across providers, and most small SaaS products get by killing the local session on logout instead. It tends to become a requirement only once a specific enterprise customer's security team asks for it explicitly.
How long does adding real SSO to an app take?
A single OIDC connection against one test identity provider can be working in a few days. Production-ready, multi-tenant support for both SAML and OIDC, with self-serve admin configuration and JIT provisioning, is usually measured in weeks, plus ongoing time to handle each new customer's identity provider quirks.
How did this land?
About the author

Developer Advocate
Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.


