“Should we use SAML or OAuth for single sign-on?” It sounds like a fair question and it is slightly malformed, which is why it causes so many muddled design meetings. These protocols were built to answer different questions. Once you see which question each answers, the choice is usually obvious, and I will say plainly where I land.
Two questions that sound alike
Authentication asks “who is this person?” Authorisation asks “what may this party do?” Single sign-on is mainly the first question: log in once at a central place, and several applications accept that result. Delegated access is mainly the second: let one application act on your behalf at another, without handing over your password.
Hold on to that split. The rest follows from it.
SAML 2.0: the enterprise workhorse
SAML was designed for browser-based single sign-on between organisations and their software. Two roles matter: the identity provider (IdP), where users actually authenticate, and the service provider (SP), the application that wants to know who they are. A user visits the application, is redirected to the IdP, logs in, and is sent back carrying a signed XML document called an assertion. The assertion says who the user is, when they authenticated, and may carry attributes such as email or department. The application checks the signature, trusts the IdP’s word, and creates a session.
Strengths: mature, widely supported by enterprise SaaS products, rich attribute handling, and a clear trust relationship set up in advance by exchanging metadata. Weaknesses: XML signature processing is intricate and has produced real implementation bugs, so use a well-maintained library and never hand-roll the parsing. It is also awkward for mobile apps and single-page applications.
OAuth 2.0: a valet key, not an ID card
OAuth 2.0 is a framework for delegated authorisation. Take a familiar case: a budgeting app wants to read your bank statements. Instead of asking for your net-banking password, it sends you to the bank, where you log in and approve a narrow permission, called a scope, such as “read transactions”. The bank gives the app an access token. The app presents that token to the bank’s API. It never sees your password, the permission is limited, and you can revoke it later.
Notice what the access token says: “the bearer may do these things”. It was not designed to tell the app who you are. Treating possession of an access token as proof of identity is a classic design error, because a token issued to some other app could be replayed, and the token’s format is not guaranteed to be readable by the client at all.
OpenID Connect: the missing identity layer
OpenID Connect, usually written OIDC, sits on top of OAuth 2.0 and adds exactly what was missing: a standard ID token, typically a signed JWT, that states who the user is, who issued the token, which application it was meant for, and when it expires. It also defines a standard way to fetch user profile information. This is what a “Sign in with Google” or an enterprise login button on a modern app usually uses.
So the real comparison for logging users in is SAML versus OIDC. OAuth by itself is the plumbing under OIDC, and it remains the right tool when the problem is API access.
Side by side
| SAML 2.0 | OAuth 2.0 | OpenID Connect | |
|---|---|---|---|
| Main purpose | Web single sign-on | Delegated access to APIs | Sign-in built on OAuth |
| Token or document | Signed XML assertion | Access token (format varies) | ID token, usually a JWT |
| Typical fit | Older enterprise SaaS, workforce portals | Apps calling APIs on a user’s behalf | Modern web, mobile and single-page apps |
| Weak spot | XML handling, mobile unfriendliness | Misused as authentication | Token validation mistakes |
Where I would land, and why
My opinion: for anything new, choose OIDC. It is simpler to implement correctly, works across browsers, phones and APIs, and is well supported by every major identity provider. Keep SAML where a vendor product only speaks SAML, which is common with older enterprise tools, and do not rewrite working integrations for fashion’s sake. The honest answer in a real organisation is “both”, fronted by one identity provider so that people have a single account, a single place to enforce multi-factor authentication, and a single switch to turn off when someone leaves.
That last point is the real prize. Federation matters less as a technical fashion than as an offboarding control. When an employee resigns, disabling one account in the identity provider ends access to dozens of applications at once, rather than leaving forgotten local accounts behind.
Mistakes worth knowing by name
- Not checking the audience or issuer of a token, so a token meant for a different application is accepted.
- Accepting unsigned or weakly validated assertions or tokens.
- Redirect URI rules that are too loose, letting an authorisation code be sent to an attacker-controlled address. Register exact redirect addresses.
- Requesting broader scopes than the application needs, so a stolen token can do far more than expected.
- Long-lived tokens with no revocation path.
One more distinction: none of these protocols decides what a user may do inside your application. They tell you who arrived, and perhaps their group claims. Your application still enforces access rules on its own data. Skipping that step is how a perfectly federated login ends up in a broken access control finding.
Leave a Reply