OAuth 2.0, OpenID Connect and API keys

Lesson 6.2 · 6 min read · by Vinay C

We'll cover the following

OAuth 2.0 and OpenID Connect

  • OAuth 2.0 is delegated authorization: "let this app read my Google Calendar" without sharing your password.
  • "Sign in with Google" is OpenID Connect (OIDC), a thin layer on top of OAuth that adds an ID token saying who you are.
  • The benefit: users do not keep a password per app. They log in once at the identity provider (IdP).

Authorization code flow in 5 steps

  1. The app redirects you to the IdP (Google) with client_id, scope, redirect_uri and a state value.
  2. You log in and consent at Google, never at the app.
  3. Google redirects back to the app with a short-lived code.
  4. The app's backend swaps the code plus its client secret for tokens over a direct server-to-server call (the back channel).
  5. The app receives an access token (plus an ID token and a refresh token) and uses them.

Why a code and not the token directly? The browser URL can leak (history, logs, referrers), so the real token never travels through it. Mobile and single-page apps have no safe place for a client secret, so they add PKCE: a one-time random verifier whose hash is sent up front and proven at the swap, so a stolen code is useless.

IdP, OIDC, JWT, SSO: four different levels

TermWhat it isLevel
IdPThe server that knows who you are and logs you in (Google, Okta, Auth0)A *who*
OIDC / OAuth 2.0The rules for how an app talks to the IdP: redirect, code, token exchangeA *protocol*
JWTThe signed format a token can haveA *format*
SSOThe experience: log in once at the IdP, and many apps accept it without asking againA *goal*

ID token vs access token

ID tokenAccess token
Answers"Who is this user?""May the bearer call this API?"
Meant forThe app (client)The API (resource server)
FormatAlways a JWT (OIDC requires it)OAuth does not say. Opaque at Google, often a JWT at Auth0, Okta and Azure.
App checksSignature via the IdP's JWKS keys, iss, aud (is it for me?), expThe app treats it as an opaque string and just forwards it

How does an API validate an opaque token? It cannot alone. It calls the IdP's introspection endpoint ({active, sub, scope, exp}, often cached briefly) or looks it up in a shared store. A JWT is verified locally with the public key. So: JWT = fast, stateless validation but hard to revoke. Opaque = a lookup per request but instant revocation.

API keys

  • Identify an application or project, not a user. Mostly server-to-server.
  • A static secret with no expiry by default, so a leaked key is a compromise until it is rotated. Keep keys server-side, never in client code, and rotate them.
  • Typical uses: rate limiting, billing, quotas.
  • Stronger options for service-to-service: the OAuth client credentials flow, or mTLS.
  • A term heard in passing: "offline ticket". It is probably the refresh token, which OAuth issues with the offline_access scope so an app can get new tokens while the user is away.

Summary: say it in the interview

  • "Social login via OAuth/OIDC authorization code flow with PKCE. API keys only for app identification and quotas, not for user identity."
  • Full one-liner: "Short-lived JWT plus revocable refresh tokens verified at the gateway, social login via OAuth/OIDC code flow with PKCE, API keys only for app identification and quotas."