OAuth 2.0 is a staple in modern API security, so interviewers will test both your conceptual grounding and your ability to apply it in real projects. Below are the questions you’ll most often hear, organized by difficulty, along with concise spoken answers that fit in a 45‑90 second window. After each answer, note the typical follow‑up the interviewer may ask to dig deeper.

Basic Concepts

What is OAuth 2.0 and why do we use it?

OAuth 2.0 is an authorization framework that lets a user grant a third‑party app limited access to their resources without sharing credentials. It separates authentication (who you are) from authorization (what you can do), reducing the attack surface for password reuse and enabling fine‑grained permissions.

Typical follow‑up: "How does OAuth differ from OpenID Connect?"

Explain the main OAuth 2.0 grant types.

  • Authorization Code – used by server‑side web apps; involves a short‑lived code exchanged for an access token.
  • Implicit – designed for pure browser‑based apps; returns the token directly in the fragment (now discouraged).
  • Client Credentials – machine‑to‑machine; the client authenticates itself and receives a token.
  • Resource Owner Password Credentials – legacy flow where the app collects the user’s password; only for trusted apps.
  • Refresh Token – allows a client to obtain a new access token without user interaction.

Typical follow‑up: "When would you prefer the client‑credentials flow over the authorization‑code flow?"

What is a scope in OAuth 2.0?

A scope is a space‑separated string that describes the permissions an access token grants. For example, read:orders write:orders tells the API that the token can read and create orders. Scopes are defined by the resource server and enforced at runtime.

Typical follow‑up: "Can a client request scopes it doesn’t need? What happens then?"

Intermediate Topics

Describe the token lifecycle.

  1. Issuance – after a successful grant, the authorization server issues an access token (often a JWT) and optionally a refresh token.
  2. Use – the client includes the access token in the Authorization: Bearer header for each API call.
  3. Expiration – access tokens have a short TTL (minutes to hours). When they expire, the client uses the refresh token to obtain a new one.
  4. Revocation – the client or resource server can call the revocation endpoint to invalidate a token before its expiry.

Typical follow‑up: "How would you handle token revocation in a distributed microservice architecture?"

How does PKCE improve security for public clients?

Proof Key for Code Exchange (PKCE) adds a secret derived from a random code verifier to the authorization request. The server stores a hashed version (code challenge). When the client exchanges the authorization code for a token, it must present the original verifier. This prevents interception attacks where a malicious app swaps the code for its own token.

Typical follow‑up: "Do you need PKCE for confidential clients? Why or why not?"

What is token introspection and when would you use it?

Token introspection is an endpoint where a resource server can POST a token and receive metadata about its validity, scopes, and expiration. It’s useful when tokens are opaque (not JWT) or when the resource server needs real‑time revocation checks.

Typical follow‑up: "How does introspection differ from simply verifying a JWT signature?"

Senior‑Level Design Questions

How would you design a multi‑tenant OAuth 2.0 system?

  1. Tenant Isolation – keep each tenant’s client registrations, scopes, and keys in separate logical partitions.
  2. Dynamic Scoping – allow tenants to define custom scopes that map to their own resource models.
  3. Policy Engine – enforce per‑tenant policies for token lifetimes, refresh token usage, and revocation windows.
  4. Auditing – log grant events with tenant identifiers for compliance.
  5. Scalability – use a stateless token format (JWT) for forward‑compatible validation, backed by a distributed cache for revocation lists.

Typical follow‑up: "What trade‑offs do you consider when choosing JWT vs opaque tokens in this scenario?"

Explain the security considerations around refresh tokens.

  • Storage – treat refresh tokens like passwords; store them encrypted on the client (e.g., iOS Keychain, Android Keystore).
  • Rotation – issue a new refresh token on each use and invalidate the previous one to limit replay attacks.
  • Scope Limitation – restrict refresh tokens to a minimal set of scopes; avoid granting overly broad permissions.
  • Revocation – provide an endpoint for immediate revocation, and consider short lifetimes for high‑risk clients.

Typical follow‑up: "How would you detect a compromised refresh token in production?"

How do you mitigate token replay attacks?

  • Bind tokens to a client identifier – include the client ID in the token’s claims and verify it on every request.
  • Use TLS everywhere – ensures the token isn’t exposed in transit.
  • Short‑lived access tokens – limit the window an attacker can reuse a stolen token.
  • Audience claim – embed the intended resource server(s) and reject tokens presented elsewhere.
  • Replay detection – maintain a nonce or jti (JWT ID) store to reject duplicate token IDs.

Typical follow‑up: "What impact does adding a nonce have on stateless validation?"

Practical Coding Examples

Sample code: Exchanging an authorization code for a token (Python, requests)

import requests

client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
redirect_uri = "https://myapp.com/callback"
code = "AUTHORIZATION_CODE_FROM_QUERY"

token_url = "https://auth.example.com/oauth/token"

payload = {
    "grant_type": "authorization_code",
    "code": code,
    "redirect_uri": redirect_uri,
    "client_id": client_id,
    "client_secret": client_secret,
}

resp = requests.post(token_url, data=payload)
resp.raise_for_status()
access_token = resp.json()["access_token"]
print("Access token:", access_token)

The snippet shows the minimal steps: send a POST, include the code and client credentials, and extract the token.

Sample spoken answer for a senior question

"When I designed the OAuth layer for a SaaS platform, I chose JWTs for their stateless verification, but I also added a short‑lived revocation cache because we needed immediate revocation for compromised tokens. The trade‑off was a slight increase in cache reads, which we mitigated by sharding the cache across our existing Redis cluster. This approach let us keep token validation fast while satisfying compliance requirements for real‑time revocation."

Comparison Table

FeatureJWT (self‑contained)Opaque Token
ValidationSignature verification onlyIntrospection endpoint required
RevocationNeeds a blacklist or short TTLImmediate via revocation endpoint
SizeLarger (payload + signature)Small (random string)
Use caseHigh‑throughput, stateless servicesTight security, frequent revocation

How to practice this

  1. Record yourself – use Call Assistant to capture your spoken answers, then replay to check pacing and clarity.
  2. Simulate follow‑ups – after each answer, write a one‑sentence follow‑up and answer it aloud; repeat until the chain feels natural.
  3. Map to your resume – pick a real project where you implemented OAuth, and rehearse the story, grounding each step in the actual impact you delivered.

FAQ

  • Q: Do I need to implement every OAuth grant type for a new API? A: No. Choose the flow that matches your client type. Most web apps use authorization code with PKCE; machine‑to‑machine services use client credentials.
  • Q: Is it safe to store refresh tokens in a browser’s local storage? A: Generally not. Browsers are vulnerable to XSS, so refresh tokens should be kept in HTTP‑only cookies or a secure storage mechanism.
  • Q: Can I mix OpenID Connect and plain OAuth in the same app? A: Yes. OpenID Connect builds on OAuth 2.0, adding an ID token for authentication. You can request both access and ID tokens in a single authorization request.
  • Q: What is the biggest mistake candidates make when answering OAuth questions? A: Over‑explaining the protocol without tying it to a concrete scenario. Interviewers want to see that you can apply the concepts, not just recite definitions.

Frequently asked questions

Do I need to implement every OAuth grant type for a new API?

No. Choose the flow that matches your client type. Most web apps use authorization code with PKCE; machine‑to‑machine services use client credentials.

Is it safe to store refresh tokens in a browser’s local storage?

Generally not. Browsers are vulnerable to XSS, so refresh tokens should be kept in HTTP‑only cookies or a secure storage mechanism.

Can I mix OpenID Connect and plain OAuth in the same app?

Yes. OpenID Connect builds on OAuth 2.0, adding an ID token for authentication. You can request both access and ID tokens in a single authorization request.

What is the biggest mistake candidates make when answering OAuth questions?

Over‑explaining the protocol without tying it to a concrete scenario. Interviewers want to see that you can apply the concepts, not just recite definitions.

#concept questions#OAuth 2.0#security#interview prep#API design