FastAuth¶
Pluggable, NextAuth-inspired authentication for FastAPI. Mount a complete auth system — providers, adapters, JWT, RBAC — in a few lines, without locking you into an ORM.
Install¶
standard includes FastAPI, joserfc + cryptography (JWT), SQLAlchemy + aiosqlite, and argon2-cffi. Other extras: oauth, webauthn, email, redis, postgresql, cli, all. See Installation.
The smallest FastAuth app¶
from contextlib import asynccontextmanager
from fastapi import Depends, FastAPI
from fastauth import FastAuth, FastAuthConfig
from fastauth.adapters.sqlalchemy import SQLAlchemyAdapter
from fastauth.api.deps import require_auth
from fastauth.providers.credentials import CredentialsProvider
from fastauth.types import UserData
adapter = SQLAlchemyAdapter(engine_url="sqlite+aiosqlite:///./auth.db")
auth = FastAuth(FastAuthConfig(
secret="change-me-in-production-min-32-bytes!!",
providers=[CredentialsProvider()],
adapter=adapter.user,
token_adapter=adapter.token,
))
@asynccontextmanager
async def lifespan(app: FastAPI):
await adapter.create_tables()
yield
app = FastAPI(lifespan=lifespan)
auth.mount(app)
@app.get("/dashboard")
async def dashboard(user: UserData = Depends(require_auth)):
return {"hello": user["email"]}
Run with uvicorn main:app --reload.
Next steps¶
- Quickstart — end-to-end in 5 minutes
- Configuration — every config field
- Concepts — how FastAuth is wired
- Protecting routes —
require_auth,require_role,require_permission - Examples — runnable apps