21 bite-sized beginner tutorials (Web Basics, APIs & Data), the 8-backend blog engine series, 4 blog frontends, 2 React starters, 3 NixOS desktops and 4 Rust API/pipeline boilerplates. Every folder is a complete, self-contained project with its own README. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VGNxPf9PrSG2kzrxSvn45Y
1.3 KiB
1.3 KiB
Auth via Auth0
Replaces the built-in email/password auth with Auth0. Auth0 issues RS256 access tokens; the API verifies them against your tenant's JWKS, checking issuer and audience. One file, no Auth0 SDK.
Install
- In the Auth0 dashboard, create an API — its identifier becomes your audience.
- Add the RS256 backend:
uv add "pyjwt[crypto]" - Copy
auth0_auth.pytoapp/auth0_auth.py - In
app/posts.py, change one import:from .auth0_auth import current_user_id - Set
AUTH0_DOMAIN(e.g.your-tenant.us.auth0.com) andAUTH0_AUDIENCE(the API identifier from step 1).
Delete / adjust
app/auth.pyand its router registration inapp/main.py— Auth0 replaces/auth/registerand/auth/login.- The
userscollection and its email index inapp/db.py— Auth0 stores your users. posts.author_idnow holds an Auth0 user id (a string likeauth0|64ef…) instead of an ObjectId string. It was already stored as a string, so nothing to migrate — only the id format changes.AUTH_SECRETis unused.
Clients obtain tokens through any Auth0 flow (Authorization Code + PKCE for
SPAs; the API's Test tab issues one for quick manual checks) and send them
as Authorization: Bearer <token>.