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.
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:
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.
OIDC is a thin, standardized profile on top of OAuth 2.0. It adds:
sub, iss, aud, exp, iat)./.well-known/openid-configuration, so clients can configure
themselves from a single URL.openid, profile, and email.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 is the default for web, mobile, and single-page applications. In short:
client_id, redirect_uri, scope, state, and a PKCE code_challenge.code and the
original state.code (plus the PKCE code_verifier) at the token
endpoint for an access token and an ID token.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.
exp.iss, aud, exp, and nonce before trusting a single claim.state. Without it, the callback is open to CSRF. With OIDC,
also validate nonce to prevent token replay.localStorage. Any XSS reads them. Prefer
HttpOnly, Secure, SameSite cookies with a backend-for-frontend, or
in-memory tokens with silent refresh.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.