Full answer
Roles in OAuth 2.0
- Resource owner: the user.
- Client: the application that wants access (for example a study planner that reads your Google Calendar).
- Authorisation server: issues tokens after the user consents (Google's accounts service).
- Resource server: the API that accepts tokens (Google Calendar API).
OAuth is about authorisation (delegated access, limited by scopes such as calendar.readonly), not about proving who the user is.
Authorisation code flow with PKCE
- The client creates a random
code_verifierand sends its hash, thecode_challenge, with the user to the authorisation server:/authorize?response_type=code&client_id=..&redirect_uri=..&scope=..&state=..&code_challenge=..&code_challenge_method=S256. - The user signs in and consents.
- The authorisation server redirects back with a short-lived
code(and the samestate, which the client checks to prevent cross-site request forgery). - The client exchanges the code plus the original
code_verifierat the token endpoint for an access token (and often a refresh token). - The client calls the API with
Authorization: Bearer <access_token>.
PKCE ensures that an attacker who intercepts the code cannot exchange it without the verifier, which matters for mobile and single-page apps that cannot keep a client secret. The older implicit flow, which returned tokens in the URL, is no longer recommended.
For machine-to-machine access with no user, the client credentials flow exchanges the client's own credentials for a token.
OpenID Connect (OIDC)
OIDC adds authentication: request the openid scope and the token response includes an ID token, a signed JWT with claims such as sub (stable user ID), email, iss (issuer), aud (your client ID) and exp. Your application validates the signature, issuer, audience and expiry, then creates its own session. Access tokens are for calling APIs; ID tokens are for your app to learn who logged in. Do not send ID tokens to APIs as access tokens.
Mutual TLS for services
In normal TLS only the server shows a certificate. In mTLS both sides do:
- The client service connects and checks the server's certificate against a trusted internal certificate authority.
- The server requests and verifies the client's certificate.
- Both now know each other's identity (for example
spiffe://schoolabe/payments), and traffic is encrypted.
Service meshes (Istio, Linkerd) issue short-lived certificates automatically and rotate them, so application code does not handle keys. Authorisation policies then say "only the checkout service may call payments".
How they combine
Users sign in with OIDC; the front end calls APIs with OAuth access tokens; services call each other over mTLS, passing the user's token or a derived one when the downstream service needs the user context. Network location alone is never trusted.
By level
Fresher: Explain that OAuth lets an app access your data elsewhere without your password, and OIDC tells the app who you are. A fresher should describe the redirect to the sign-in page and back.
Mid: Walk through the code flow with PKCE, validate ID tokens and explain client credentials. Describe how mTLS works between services.
Senior: Discuss refresh token rotation, token exchange, service mesh certificate management, authorisation policies between services and zero-trust design. Expect precise token handling rules.
Key points
- OAuth 2.0 delegates limited access with scoped tokens
- OIDC adds an ID token that says who the user is
- Authorisation code flow with PKCE for browser and mobile apps; state prevents CSRF
- Client credentials for machine-to-machine
- mTLS gives both services certificates for identity and encryption
Common mistakes
- Using OAuth access tokens as proof of identity without OIDC
- Using the implicit flow in new apps
- Skipping validation of issuer, audience and expiry on ID tokens
- Trusting internal traffic because it is inside the network
Follow-ups
- How do refresh token rotation and reuse detection work?
- How would you revoke a compromised service certificate?
- When should a backend exchange a user token for a downstream token?
Tips
- Name the four OAuth roles
- Walk through PKCE step by step
- Separate ID tokens from access tokens
Evaluation rubric
- Correct OAuth roles and flows
- PKCE and state explained
- Correct OIDC ID token use and validation
- mTLS mechanics and zero-trust context