Lion Cipher Lab

Enforce API authorization at the gateway (validate the JWT before it reaches your service)

Why it matters

The moment you have more than one backend service, a hard question appears: where does 'is this caller allowed in?' get enforced? If every service reimplements token validation, you get five slightly different, slightly wrong implementations — one forgets to check `exp`, one forgets `aud`, one accepts `alg: none` — and rotating a key means editing five codebases. The industry answer is to centralize the coarse check at a gateway or reverse proxy: one consistent choke point that authenticates the caller, validates the token's signature and claims, rate-limits, and logs — once, in front of…

What you'll learn

Steps in this lab

  1. The idea: one choke point instead of five copies of the same check
  2. Lay out the project and write the backend (deliberately unprotected)
  3. Write the auth service: validate the JWT the RIGHT way with PyJWT
  4. Write the gateway config: auth_request calls the auth service on every request
  5. Wire it together with Compose — and keep the backend OFF the public network
  6. Prove the three outcomes: no token -> 401, valid -> backend, tampered/expired -> 401
  7. Prove nobody can bypass the gateway (the private-network check)
  8. The judgment: what the gateway fixes, what it never will, and the common mistakes

Open the full interactive lab →