A FastAPI dependency
Depends(authdog.session) resolves the request's session and returns a typed AuthdogContext with token, user, and is_authenticated for any path operation.
- Typed AuthdogContext
- Any path operation
Python · FastAPI · Flask · Django · Starlette · aiohttp
A session resolver, a require_auth gate, and a logout handler for Python backends, with idiomatic bindings for FastAPI, Flask, Django, Starlette, and aiohttp over one shared core. Validate Authdog sessions on every request, on the same wire as the Node SDKs.
Add the dependency
# main.py
from authdog.fastapi import Authdog
authdog = Authdog(public_key=os.environ["PK_AUTHDOG"])
@app.get("/")
async def index(ctx=Depends(authdog.session)):
return {"authenticated": ctx.is_authenticated}
Gate routes with require_auth
# routes.py
@app.get("/me")
async def me(user=Depends(authdog.require_auth)):
return user
Your framework, one core
A drop-in session resolver, a require_auth gate, and a typed context, delivered as a FastAPI dependency, a Flask decorator, Django/Starlette middleware, or an aiohttp middleware, all wire-compatible with the rest of your Authdog stack.
Depends(authdog.session) resolves the request's session and returns a typed AuthdogContext with token, user, and is_authenticated for any path operation.
Depend on authdog.require_auth and FastAPI raises HTTPException(401) for unauthenticated requests, returning the user object otherwise. This is the security boundary.
The resolved context is cached on request.state, so combining session and require_auth on one request makes a single outbound userinfo call.
Import authdog.fastapi, authdog.flask, authdog.django, authdog.starlette, or authdog.aiohttp. Each is idiomatic for its framework and shares the same core, cookie parsing, and userinfo flow.
authdog.logout(request) returns a RedirectResponse that expires the session cookie and redirects to a redirect_uri sanitized against open redirects.
It mirrors @authdog/express and @authdog/fastify on the wire, so one Authdog environment serves your Node and Python services interchangeably.
Bindings
One package, one shared core. Install the extra for your stack and get idiomatic bindings.
A session resolver, a require_auth gate, and a logout handler as first-class FastAPI dependencies.
A session-resolving middleware and a require_auth view decorator, wired into the Django request lifecycle.
A session resolver cached on flask.g and a require_auth decorator. Plain Flask, secure by default.
ASGI middleware that resolves the session and a require_auth dependency for pure Starlette apps.
An aiohttp middleware and a require_auth wrapper that gate handlers on the same shared core.
pip install the extra for your framework, e.g. authdog[fastapi].
Add the session dependency or middleware for your stack.
Depend on require_auth where a user is required.
pip install the SDK, import the binding for your framework, and gate your routes with require_auth today. Free to start, with secure defaults built in.