Blog

Cost effective solutions

Productive meetings with fast deliveries

24/7 support with sameday response

OAuth 2.0 and OpenID Connect, explained

Posted by vladimir gorea on Fr 27 November 2026 Updated on Fr 27 November 2026

Intro

OAuth 2.0 and OpenID Connect (OIDC) are two different things that are constantly mentioned in the same sentence. OAuth 2.0 is about delegated authorization: letting an application act on a resource on behalf of a user without ever seeing the user's password. OIDC is about authentication: proving who the user is, via a standard layer on top of OAuth 2.0.

Confusing the two is the source of a surprising number of security bugs. This post walks through the pieces, the main flow, and the pitfalls worth knowing.

OAuth 2.0: delegation, not login

Before OAuth, a third-party app that wanted to read your calendar had to ask for your password. OAuth replaced that with a consent screen and a scoped, revocable token. The core roles are:

  1. Resource owner - the user.
  2. Client - the application requesting access.
  3. Authorization server - issues tokens after the user consents.
  4. Resource server - accepts the token and serves the protected resource.

The client gets an access token, which it presents to the resource server. Access tokens are usually short-lived and scoped. A refresh token lets the client obtain new access tokens without involving the user again.

OAuth deliberately says nothing about who the user is. It only says what the client is allowed to do. If you use it for login, you are improvising.

OpenID Connect: authentication on top

OIDC is a thin, standardized profile on top of OAuth 2.0. It adds:

The critical rule: the ID token is for the client, the access token is for the resource server. They are not interchangeable.

The authorization-code flow with PKCE

The authorization-code flow is the default for web, mobile, and single-page applications. In short:

  1. The client redirects the user to the authorization endpoint with a client_id, redirect_uri, scope, state, and a PKCE code_challenge.
  2. The user authenticates and consents.
  3. The authorization server redirects back with a short-lived code and the original state.
  4. The client exchanges the code (plus the PKCE code_verifier) at the token endpoint for an access token and an ID token.
  5. The client validates the ID token and, optionally, calls UserInfo.

PKCE (Proof Key for Code Exchange) binds the code to the client that requested it, which closes the interception hole that made the implicit flow dangerous. For public clients - anything that cannot keep a secret, like a browser app or a mobile app - PKCE is mandatory.

Tokens, briefly

Common pitfalls

  1. Using OAuth for login without OIDC. You end up inventing a userinfo call and a session model. Use OIDC.
  2. The implicit flow. Tokens in fragment URLs leak through history, logs, and referrers. Use authorization code + PKCE.
  3. Skipping state. Without it, the callback is open to CSRF. With OIDC, also validate nonce to prevent token replay.
  4. Storing tokens in localStorage. Any XSS reads them. Prefer HttpOnly, Secure, SameSite cookies with a backend-for-frontend, or in-memory tokens with silent refresh.
  5. Broad scopes. Request the minimum. A token that can read everything is a token that will eventually be abused.
  6. Trusting the ID token on the resource server. The resource server should validate access tokens; the ID token is for the client's session.

When to use which

The takeaway is simple: OAuth grants access, OIDC establishes identity. Keep them separate in your head and in your code, and most of the classic mistakes disappear.

What’s your Project About?

We would love to know about your line of business and how we can help you grow!
Tell Us About Your Project