Q36: Walk through the exact step-by-step algorithm an API performs to verify a JWT.
When an API receives an incoming HTTP request carrying Authorization: Bearer <token>, it executes the following sequential steps:
- Format Split: Split the token string into Header, Payload, and Signature components via dot (
.) delimiters. - Header Parse: Base64URL-decode Header; inspect
algandkidparameters. - Algorithm Check: Confirm
algmatches explicitly permitted algorithms (e.g., RS256). Rejectnoneor unexpected algorithms. - Public Key Retrieval: Fetch matching public key from memory or JWKS endpoint matching
kid. - Cryptographic Check: Compute cryptographic signature over
header + "." + payloadand verify it against the provided signature string. - Claim Validations: Verify
exp > current_time,nbf < current_time,issmatches expected issuer, andaudmatches expected audience.
Key Takeaways
Signature check confirms the payload was not tampered with.
Claim checks (
exp,iss,aud) confirm the token is timely and intended for the receiving API.