Skip to main content
πŸ”’ Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial β†’
⚑
← Coursesβ€ΊFastAPI ProductionModule 2 Β· Auth + Security Β· Recapβ€ΊπŸŽ― Review: FastAPI module 2 recapscenario43 / 105
+80 XP
Task
Build a small `check_jwt(token, now)` helper that ties 4 module-2 ideas together: 1. **Format** β€” must have exactly 3 dot-separated parts; else return None. 2. **Decode payload** β€” middle segment is base64url-encoded JSON. 3. **Expiry** β€” payload `exp` (unix seconds) must be > `now`; else None. 4. **Subject** β€” return `payload["sub"]` (the user_id). The `now` parameter is injected so tests stay deterministic β€” a fake-clock pattern you'll reuse in module 3. The harness prints results for: valid token / expired / malformed (only 2 parts) / missing exp.
✏️ Write your code here
🐍
Loading Python...
One-time download (~1 MB). Then it runs instantly.
πŸ“Š Result
Press Run to see result...

πŸ’¬ Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…