SAML vs OAuth vs OpenID Connect
SAML, OAuth 2.0, and OpenID Connect are three of the most widely used standards for federated identity, and they are frequently confused because their scopes overlap and their names appear side by side in login systems. The critical distinction is that SAML and OpenID Connect handle authentication, proving who a user is, while OAuth 2.0 handles authorization, granting an application limited access to resources. Choosing correctly, and combining them safely, depends on understanding what each protocol was actually designed to do.
OAuth 2.0: Delegated Authorization
OAuth 2.0 is an authorization framework. Its purpose is to let a user grant one application limited access to their data held by another service, without sharing a password. When you allow a photo-printing app to read your cloud photos, OAuth issues the app a scoped access token instead of your credentials.
The framework defines four roles:
- Resource owner: the user who owns the data.
- Client: the application requesting access.
- Authorization server: issues tokens after the user consents.
- Resource server: the API that holds the data and accepts tokens.
The most common flow is the authorization code grant:
- The client redirects the user to the authorization server with requested scopes.
- The user authenticates and consents to the requested access.
- The authorization server returns a short-lived authorization code to the client's redirect URI.
- The client exchanges that code, plus its own credentials, for an access token at the token endpoint.
- The client presents the access token to the resource server to call the API.
The key point for security reviewers is that OAuth by itself says nothing about the user's identity. An access token is a bearer credential granting API access; it is not proof of who logged in. Treating a raw OAuth access token as authentication is a classic mistake that can lead to account confusion and token substitution vulnerabilities.
OpenID Connect: An Identity Layer on OAuth
OpenID Connect (OIDC) fills exactly that gap. It is a thin identity layer built on top of OAuth 2.0, adding authentication in a standardized way. Alongside the access token, the authorization server issues an ID token.
The ID token is a JSON Web Token (JWT) containing signed claims about the authentication event:
iss(issuer) identifies the provider that authenticated the user.sub(subject) is a stable unique identifier for the user.aud(audience) names the client the token was issued for.expandiatbound the token's validity in time.nonceties the token to the original request to prevent replay.
Decoded, an ID token payload is simply signed JSON:
{
"iss": "https://idp.example.com",
"sub": "248289761001",
"aud": "client-app-id",
"exp": 1710000900,
"iat": 1710000600,
"nonce": "n-0S6_WzA2Mj"
}
Because OIDC reuses OAuth's flows and adds a well-defined identity token plus a standard userinfo endpoint, it has become the common choice for modern web and mobile single sign-on. It gives applications both authentication (the ID token) and authorization (the access token) in one round trip.
SAML: XML-Based Enterprise Federation
Security Assertion Markup Language (SAML) 2.0 predates OIDC and solves the same authentication problem using XML. A SAML assertion is an XML document, signed by the identity provider, stating that a user has authenticated and carrying attributes such as name, email, and group membership.
SAML's typical web browser SSO uses HTTP redirects and form POSTs to move the assertion from the identity provider to the service provider. Its signing and validation rely on XML Digital Signatures over the assertion.
SAML remains entrenched in enterprise environments and SaaS integrations because of its maturity and rich attribute handling. Its main drawbacks are the verbosity of XML, the operational complexity of certificate management, and a history of parser-related vulnerabilities, notably XML signature wrapping, where an attacker restructures the document so a validator checks a legitimately signed element while the application reads an attacker-controlled one.
Comparing the Three
The protocols answer different questions, and the following comparison clarifies when each applies.
- Primary purpose: OAuth grants authorization; SAML and OIDC assert authentication.
- Token format: SAML uses XML assertions; OAuth and OIDC use JSON, with OIDC's ID token being a JWT.
- Typical use: SAML dominates legacy enterprise web SSO; OIDC suits modern apps, single-page apps, and mobile; OAuth underlies API access delegation for both.
- Transport: SAML leans on browser redirects and POST; OAuth and OIDC use RESTful HTTP with JSON.
A practical rule: if you need to prove identity for login, reach for OIDC or SAML. If you need to call an API on a user's behalf, reach for OAuth. All three are common mechanisms behind single sign-on.
Security Considerations Across Protocols
Each standard has recurring pitfalls worth auditing.
Validate Tokens Rigorously
For OIDC and OAuth, always verify the JWT signature against the provider's published keys, and check iss, aud, exp, and nonce. Never accept a token whose signature algorithm is set to none, and do not trust unsigned claims.
Protect the Flows
- Use the authorization code flow with PKCE for public clients such as mobile and single-page apps, which defends against code interception.
- Register exact redirect URIs to prevent open-redirect token leakage.
- Keep access tokens short-lived and scope them narrowly.
Guard Against SAML-Specific Attacks
- Validate signatures over the correct elements and reject documents with wrapped or duplicated assertions.
- Enforce audience restriction and assertion expiry to stop replay.
- Pin trusted signing certificates and rotate them deliberately.
Because these protocols issue tokens that grant broad access, they must be paired with strong session management once the user is logged in, ensuring a stolen token cannot be replayed indefinitely.
Key Takeaways
- OAuth 2.0 is for authorization; SAML and OpenID Connect are for authentication.
- OpenID Connect adds an ID token, a signed JWT, on top of OAuth to standardize proof of identity.
- SAML uses signed XML assertions and remains common in enterprise SSO despite XML complexity.
- Never treat a raw OAuth access token as evidence of who the user is.
- Rigorous token validation, PKCE, exact redirect URIs, and defense against XML signature wrapping are essential across these protocols.