Skip to the page

Authentication in the frontend · senior

OAuth 2.0 and OpenID Connect with PKCE, at a frontend level

OAuth gives an app an access token to call an API on the user's behalf, OpenID Connect adds an ID token that says who the user is, and browser and mobile apps must use the Authorization Code flow with PKCE (the implicit flow is deprecated).

The notes

What you must know

  • Roles: user, client (your app), authorization server (Google, Auth0, your IdP), resource server (the API).
  • Authorization Code + PKCE: the app makes a random code_verifier, sends code_challenge = BASE64URL(SHA256(verifier)) with method S256 in the authorize redirect, gets a short-lived code back on the redirect_uri, then exchanges code + verifier for tokens. A stolen code is useless without the verifier.
  • state: a random value checked on return; it stops login CSRF and mix-ups. OIDC nonce: binds the ID token to this login.
  • ID token (a JWT) is for the client to know who logged in; the access token is for the API. Do not send the ID token to APIs as an access token.
  • The implicit flow (tokens in the URL fragment) is deprecated: tokens leak through history, referrers and logs. RFC 10017 (2026) says browser apps should use code + PKCE and prefers a BFF for sensitive apps.
  • redirect_uri must be matched exactly by the server; loose matching plus an open redirect lets attackers steal codes. On mobile, use claimed HTTPS links (App Links / Universal Links) or the system browser (ASWebAuthenticationSession, Custom Tabs), not an embedded WebView.

The red pen

Common traps: mistake → fix

  • Mistake: "PKCE replaces the state parameter"

    Fix: PKCE protects the code exchange; state still protects against login CSRF.

  • Mistake: "The ID token is the access token"

    Fix: the ID token is for the client; APIs should get access tokens with the right audience.

  • Mistake: "SPAs should use the implicit flow because they can't keep secrets"

    Fix: that flow is deprecated; use code + PKCE (a public client) or a BFF.

Easy to hard

Questions interviewers ask, easy to hard

  1. What is the difference between OAuth 2.0 and OpenID Connect?
  2. Walk me through Authorization Code with PKCE step by step.
  3. Why PKCE? What attack does it stop?
  4. What is state for? What is nonce for?
  5. How would you implement 'Login with Google' in a React app and in a React Native app?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview