JWT Bearer Auth
Stateless, self-contained tokens with short expiry. Verify cryptographically โ no DB round-trip per request. Powered by HS256 or RS256.
A compact FastAPI reference app with a working Books API, rich request logging, and balanced guidance for authentication and deployment on AWS, GCP, and Azure.
6
Books Endpoints
3
Cloud Providers
0
Secrets in Code
from fastapi import FastAPI, Query
from pydantic import BaseModel
class BookListResponse(BaseModel):
items: list[BookResponse]
total: int
skip: int
limit: int
@app.get("/api/v1/books", response_model=BookListResponse)
async def list_books(skip: int = Query(0, ge=0), limit: int = Query(20, ge=1, le=100)):
return paginate_books(list(store.values()), skip=skip, limit=limit)What The Docs Cover
Six core topics covered by the documentation. The live demo app implements the API-focused pieces and stays intentionally small.
Stateless, self-contained tokens with short expiry. Verify cryptographically โ no DB round-trip per request. Powered by HS256 or RS256.
Zero secrets in code. IRSA on AWS, Workload Identity on GCP, Managed Identity on Azure. Your app gets short-lived tokens automatically from the platform.
Cognito (AWS), Google Identity (GCP), or Microsoft Entra ID โ enterprise login with MFA, conditional access, and app roles. JWKS-validated RS256 tokens.
Fine-grained authorization with OAuth2 scopes. Use Security() โ not just Depends() โ to cleanly enforce access per endpoint.
Separate request/response models so internal fields never leak. model_dump(exclude_unset=True) for clean partial updates.
Interactive Swagger UI and ReDoc generated from your type annotations โ no YAML to maintain. Security schemes auto-wired.
The Big Picture
These patterns are not mutually exclusive โ a production app typically uses all three simultaneously. Choose based on who or what is being authenticated.
Use when: Generic internet users โ mobile apps, SPAs, public APIs.
Use when: Your app talking to managed cloud services (databases, queues, secrets) โ zero secrets in code on any cloud.
Use when: Corporate users who authenticate via Cognito (AWS), Google Identity (GCP), or Entra ID (Azure) โ with MFA and role-based access.
Deploy Anywhere
All targets support platform-native IAM โ no long-lived credentials stored anywhere in your deployment pipeline.
Lambda ยท EKS ยท Elastic Beanstalk
Lambda
Serverless, pay-per-invocation with IRSA for secrets
EKS
Kubernetes with IRSA for per-pod IAM
Elastic Beanstalk
PaaS with one-command deploys
Cloud Run ยท App Engine ยท GKE
Cloud Run
Container-native serverless, scales to zero
App Engine
Managed PaaS with automatic scaling
GKE
Autopilot or standard Kubernetes with Workload Identity
Functions ยท App Service ยท AKS
Azure Functions
Serverless with Managed Identity built-in
App Service
PaaS with deployment slots and Key Vault refs
AKS
Kubernetes with Workload Identity Federation
Quick Start
The live demo focuses on the Books API and observability basics. Hit /docs for the interactive Swagger UI. Auth and deployment patterns are explained in the docs alongside the running demo.
INFO: ย ย Started server process
INFO: ย ย Waiting for application startup.
INFO: ย ย Application startup complete.
INFO: ย ย Uvicorn running on http://127.0.0.1:8000