Skip to content
Web Development4 min read

OAuth 2.0 vs OpenID Connect: Choosing the Right Approach for Authorisation and Sign-In

OAuth 2.0 vs OpenID Connect explained: authorisation vs authentication, access and ID tokens, which flows to use, PKCE, SAML, and common security mistakes.

01

OAuth 2.0 or OpenID Connect?

Use OpenID Connect when you need to sign users in and know who they are; use OAuth 2.0 when an application needs delegated, limited access to an API. Most modern apps use both: OIDC for sign-in, returning an ID token, and OAuth access tokens for calling APIs. Use the authorisation code flow with PKCE for user-facing apps and client credentials for machine-to-machine access, and rely on an established identity provider rather than building your own.

This guide is for developers and technical leads. For API protection, see API security best practices; for mobile sign-in, mobile app authentication.

02

Key takeaways

  • OAuth is for authorisation; OIDC adds authentication.
  • ID tokens identify users; access tokens call APIs.
  • Authorisation code with PKCE for user-facing apps.
  • Client credentials for service-to-service calls.
  • No implicit or password grants for new work.
  • Use an identity provider; validate tokens properly.
03

Comparison

AspectOAuth 2.0OpenID Connect
PurposeDelegated authorisation to APIsUser authentication (sign-in) on top of OAuth
Main tokenAccess token (plus refresh token)ID token (a signed JWT), plus OAuth tokens
Who reads the tokenThe API (resource server)The client application
User informationNot standardisedStandard claims and a UserInfo endpoint
SpecificationRFC 6749 (IETF)OpenID Connect Core 1.0 (OpenID Foundation)
04

Which flow to use

ScenarioFlow
Web app with a serverAuthorisation code (with PKCE)
Single-page appAuthorisation code with PKCE, ideally with a backend-for-frontend holding tokens
Mobile appAuthorisation code with PKCE via the system browser
Server-to-serverClient credentials
Devices without browsersDevice authorisation grant
Legacy implicit or password flowsReplace; see RFC 9700 (IETF)
05

Tokens and validation

Validate ID tokens' signature, issuer, audience, expiry and nonce before trusting them. APIs should validate access tokens and check scopes and audience. Keep access tokens short-lived, store refresh tokens securely and rotate them, and never put tokens in URLs or logs. PKCE (RFC 7636) protects the authorisation code from interception (RFC 7636). OAuth 2.1, which consolidates current practice, is still an IETF draft at the time of writing.

06

Enterprise sign-in for B2B SaaS

Business customers often require single sign-on with their identity provider through OIDC or SAML, plus automated provisioning (often SCIM) and group-to-role mapping. Plan for multiple customer identity providers per tenant, and make sure users removed by the customer lose access promptly. See SaaS roles and permissions.

07

Hypothetical example: a SaaS adding SSO and an API

This example is hypothetical. A B2B SaaS used its own passwords and shared API keys. It moved sign-in to an identity provider using OIDC with the authorisation code flow and PKCE, added SAML and OIDC single sign-on for enterprise tenants, and replaced API keys for partner integrations with OAuth client credentials and per-client scopes. The API validated access tokens and scopes on every request.

08

Common mistakes

  • Using access tokens as proof of identity.
  • Implicit flow in single-page apps.
  • Skipping ID token validation.
  • Long-lived tokens stored in browser storage.
  • Building authentication from scratch.
09
10

Conclusion

OAuth 2.0 and OpenID Connect work together: OIDC signs users in, OAuth grants API access. Use current flows, validate tokens, keep them short-lived and rely on a proven identity provider. For implementing SSO for business customers, see enterprise SSO implementation.

Adding sign-in or securing an API?

ZSpace Labs is an India-based, remote-first technology studio working with Australian and international businesses on secure web applications and APIs and mobile apps. If it would help to plan authentication for your product, we are happy to talk it through.

Start a Project
FAQ

Common questions.

OAuth 2.0 is an authorisation framework: it lets an application obtain an access token to call an API with limited permissions. OpenID Connect (OIDC) is an identity layer on top of OAuth 2.0: it adds an ID token and standard user information so an application can sign a user in and know who they are.

Get in touch

Have a project in mind?

Whether you're building a new digital product, improving an existing website, or looking to automate part of your business — let's talk.