OAuth, tokens and login providers · core
Which OAuth flow for which client, and why users get logged out
Use the authorization code flow with PKCE for apps with a user, client credentials for machines, and the device flow for TVs. Keep users signed in with refresh token rotation done safely.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Web app (SPA): authorization code with PKCE. Better, a backend-for-frontend: the server does the code exchange and keeps the tokens, and the browser holds only an httpOnly session cookie, so no token sits in JavaScript.
- Mobile app: authorization code with PKCE in the system browser (Custom Tabs, AppAuth), redirecting back through an https App Link. Never an embedded WebView, where the app could read the password. Google blocks sign-in in WebViews.
- Nightly job or service: client credentials, with no user. Prefer a private-key JWT or mTLS to a shared secret, and a token limited to one audience and a narrow scope.
- TV or device without a keyboard: the device authorization grant (RFC 8628). The TV shows a code, and the user approves on a phone.
- PKCE: the client makes a random code_verifier, sends its hash as the code_challenge (S256), and sends the verifier when exchanging the code, so a stolen code is useless.
- Logged out every hour: the access token lifetime ends and renewal fails. Silent renewal in a hidden iframe (prompt=none) needs the provider cookie in a third-party context, which Safari and users who block third-party cookies do not allow, so it returns login_required. Use refresh tokens or a BFF session.
- Several tabs: with refresh token rotation and reuse detection, two tabs refreshing with the same token look like theft, and the provider revokes the whole token family. Share the refresh across tabs (one tab refreshes, others wait) or let a BFF refresh on the server.
- Making access tokens last 24 hours widens the window for a stolen token. Fix the renewal, not the lifetime.
The red pen
Common traps: mistake → fix
Mistake: The implicit flow is fine for single-page apps
Fix: Use code with PKCE. Implicit puts tokens in URLs.
Mistake: A client secret in a mobile app is safe if obfuscated
Fix: Public clients cannot keep secrets. Use PKCE.
Mistake: Longer access tokens fix logouts
Fix: They only widen the damage of theft. Fix refresh.
Easy to hard
Questions interviewers ask, easy to hard
- Which OAuth flow do you use for a React app, an Android app, a nightly job and a TV?
- What does PKCE protect against and how does it work?
- Why is a WebView a bad place for login?
- Why do users get logged out in Safari every hour?
- Two tabs refresh at the same time and everyone is logged out. Why?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.