IAM interview questions · Protocols
How does an API validate a JWT access token?
In plain wordsA banknote: you check the watermark (signature), that it is in your currency (audience) and not withdrawn (expiry). Then you look at the amount.
How it works
Order matters. 1) Parse the header and accept only the algorithms you expect (for example RS256), never “none”, never switch from RS to HS. 2) Find the key by kid in the issuer’s JWKS, cached and refreshed on rotation. 3) Verify the signature.
4) Check the claims: iss is the expected issuer, aud contains your API, exp is in the future and nbf in the past (with a small clock skew), and, if you use them, typ and token type. 5) Only then authorize: scopes, roles, and object-level checks in your code.
Remember that a JWT is signed, not encrypted: anyone can read the payload. And it cannot be revoked by itself: keep it short-lived or check a revocation signal.
A concrete example
An attacker takes a valid token, changes "role":"user" to "role":"admin" and sends it. The signature no longer matches the payload: rejected. Then they try changing alg to "none" and removing the signature: rejected because the API only allows RS256. Finally they send a valid token issued for another API: rejected on aud.
See it in action: change the token, break the signature
..- Signature
- Expiry
- Audience
Mistakes to avoid
- Decoding the token and trusting it without verifying the signature.
- Fetching JWKS on every request, or never refreshing it.
They may also ask you
- How do you handle key rotation on the API side?
- How would you revoke a JWT before it expires?