Q36: Walk through the exact step-by-step algorithm an API performs to verify a JWT.

Difficulty:MediumTopic:JWT Mechanics

When an API receives an incoming HTTP request carrying Authorization: Bearer <token>, it executes the following sequential steps:

  1. Format Split: Split the token string into Header, Payload, and Signature components via dot (.) delimiters.
  2. Header Parse: Base64URL-decode Header; inspect alg and kid parameters.
  3. Algorithm Check: Confirm alg matches explicitly permitted algorithms (e.g., RS256). Reject none or unexpected algorithms.
  4. Public Key Retrieval: Fetch matching public key from memory or JWKS endpoint matching kid.
  5. Cryptographic Check: Compute cryptographic signature over header + "." + payload and verify it against the provided signature string.
  6. Claim Validations: Verify exp > current_time, nbf < current_time, iss matches expected issuer, and aud matches 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.