🔌 Framework Integration
jwtlib is intentionally framework-agnostic. This page shows the idiomatic
wiring used by the canonical auth-server service.
⚙️ FastAPI dependency
Expose the token from the Authorization header and resolve it to a user via
a dependency:
On any auth failure the dependency translates AuthError into a 401 — the
library never couples to the HTTP layer.
📡 Resource server / microservice
A consumer service that does not own the user database can verify tokens via introspection without a shared session store:
🧭 Routing tokens
- First-party services — use
get_logged_in_user(and theTOKEN_SECRET_KEYthey share) for a direct lookup. - Third-party / external clients — validate against the
auth-server/introspectendpoint for a standard introspection response. - Static vetoes — use
authenticate_requestwhen you only need allow/deny.
Keep Authorization: Bearer <token> consistent across all callers.
⚠️ Error mapping cheat-sheet
| Raised exception | Typical HTTP result |
|---|---|
InvalidAuthorizationHeader |
401 — malformed header |
InvalidToken |
401 — expired, bad signature, or malformed |
UserNotFound |
401 — subject no longer exists |
AuthServiceUnavailable |
503 — upstream auth unavailable |
NotAuthenticated |
401 — missing credentials |
📚 Read Next
- How to Use — the underlying coroutine flows.
- Development — contributing to
jwtlib.