Skip to main content

authwarden

A production-grade, pluggable authentication library for FastAPI.

PyPI version Python versions License: MIT Tests

JWT auth, OAuth2 across 8 providers, MFA, RBAC, and full flow flexibility — all behind a clean FastAPI router you can drop into any app.

Quickstart · Features · Documentation · Roadmap


Why authwarden

Most FastAPI auth tutorials show you a toy JWT example and stop there. authwarden is built for the parts that actually matter in production:

  • Everything is a Protocol. Bring your own database (the AbstractUserStore protocol works out of the box with SQLAlchemy, MongoDB/Beanie, SQLModel, or Tortoise — no built-in ORM lock-in), your own email/SMS provider, your own templates.
  • Flexibility where it counts. Verify by link or OTP. Notify by email, SMS, or both. Let users log in with email, username, or phone — your call, configured once.
  • Security defaults that are actually defaults. Brute-force lockout, OTP attempt limiting, encrypted OAuth tokens at rest, PKCE on every social login flow — none of it bolted on, none of it optional homework.
  • A real test suite. 390 tests across unit, flow, and full HTTP end-to-end coverage.

How it compares

authwarden is a complete auth layer: routes, flows, and a storage protocol. Authlib is a lower-level OAuth/OIDC toolkit, and authwarden uses it internally for the OAuth client. The closest alternative is fastapi-users.

authwarden fastapi-users
Project status Active Maintenance mode: security and dependency updates only
Register, login, password reset, email verification ✅ ✅
Social login 8 providers including Apple, PKCE on all ✅
MFA (TOTP + backup codes) ✅ Not in its feature list
Role hierarchy and scopes ✅ Not in its feature list
Login lockout and OTP attempt limits ✅ Not in its feature list
Cookie transport Not yet ✅
Database and Redis token strategies Not yet ✅
Built-in ORM stores Not yet (planned) ✅

Compared against the fastapi-users README as of October 2026. Check its current docs before deciding.


Features

Authentication

  • Register, login, logout, refresh (with rotation)
  • Email verification — link or OTP, your choice
  • Password reset — link or OTP, your choice
  • Change password, and set-password for OAuth-only accounts
  • Login via email, username, or phone — configurable priority order
  • Email and SMS notification channels, independently configurable

MFA

  • TOTP setup, confirm, disable
  • 8 single-use, argon2-hashed backup codes per user

Permissions

  • Role hierarchy (guest → user → moderator → admin → superadmin)
  • Arbitrary scope strings ("user:read", "admin:delete", anything you want)

OAuth 2.0 / Social Login

  • Google, GitHub, Facebook, Microsoft, LinkedIn, Discord, Twitter/X, Apple
  • PKCE (S256) on every provider, no exceptions
  • Automatic account linking (existing link → verified-email match → auto-register)
  • Apple's quirks handled for you: ES256 client-secret generation, JWKS-cached id_token verification, first-login-only name capture
  • OAuth tokens encrypted at rest

Security

  • Login lockout after configurable failed attempts
  • OTP attempt limiting with auto-invalidation
  • Anti-enumeration on password reset and resend-verification
  • Single-use, hashed reset/verification tokens — raw tokens never touch storage

Installation

pip install authwarden

Optional extras:

pip install "authwarden[redis]"   # Redis-backed sessions and token blacklist
pip install "authwarden[sns]"     # AWS SNS SMS backend
pip install "authwarden[all]"     # everything

Quickstart

from fastapi import FastAPI, Depends
from authwarden import AuthWarden, WardenConfig, MemoryUserStore

config = WardenConfig(
    secret_key="change-me-to-a-real-32-byte-secret",
    require_email_verification=False,  # skip for this example
)
store = MemoryUserStore()  # swap for your own AbstractUserStore in production
warden = AuthWarden(config=config, user_store=store)

app = FastAPI()
app.include_router(warden.router, prefix="/auth", tags=["auth"])


@app.get("/profile")
async def profile(user=Depends(warden.current_user)):
    return {"id": user.id, "email": user.email}


@app.delete("/admin/users/{user_id}")
async def delete_user(user_id: str, _=Depends(warden.require_roles("admin"))):
    ...

Run it:

uvicorn main:app --reload

Open http://127.0.0.1:8000/docs — you now have working /auth/register, /auth/login, /auth/refresh, MFA, and OAuth endpoints, plus an interactive Authorize button for testing protected routes.


Core concepts

WardenConfig

Every behavioral switch lives here — verification method (link/OTP), notification channels, login identifier order, lockout thresholds, OAuth provider credentials, and more. See the full configuration reference for every field.

AbstractUserStore

A Protocol, not a base class — any object with the right async methods satisfies it. Works with any database:

class SQLAlchemyUserStore:
    def __init__(self, session_factory):
        self.session_factory = session_factory

    async def get_by_email(self, email: str):
        async with self.session_factory() as session:
            result = await session.execute(select(UserModel).where(UserModel.email == email))
            row = result.scalar_one_or_none()
            return UserInDB.model_validate(row) if row else None
    # ... remaining protocol methods

More examples (MongoDB/Beanie, SQLModel, Tortoise) in the full docs.

Extending the user model

UserInDB supports arbitrary extra data without a migration, or full subclassing for typed fields:

class MyUser(UserInDB):
    company_id: str | None = None
    subscription_tier: str = "free"

The AuthWarden facade

  • warden.router — mount it, get 20 endpoints
  • warden.current_user — Depends()-compatible, fetches fresh from your store, checks is_active on every request
  • warden.require_roles(*roles) / warden.require_scopes(*scopes) — guard any route you write yourself

Testing

git clone https://github.com/timihack/authwarden
cd authwarden
pip install -e ".[dev]"
pytest

390 tests across foundation, auth flows, MFA/permissions, OAuth, router assembly, and full HTTP end-to-end coverage.


Documentation

This README gets you to a working quickstart. For the complete reference — every config field, every flow with code samples, every customization pattern — see the full documentation site.

Roadmap

Tracked in the project discussion — includes planned post-v1.0 work like transport/strategy pluggability, Enterprise OIDC, SAML 2.0, and built-in ORM backend implementations.

Contributing

Issues and PRs welcome. This project is in active development — check the roadmap discussion before starting major work.

License

MIT © timihack

Metadata

Release files for authwarden 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for authwarden 1.1.1
File Size Uploaded Provenance Actions
authwarden-1.1.1.tar.gz 112.7 kB With provenance Details for authwarden-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for authwarden 1.1.1
File Interpreter ABI Platform Actions
authwarden-1.1.1-py3-none-any.whl Python 3 none any Details for authwarden-1.1.1-py3-none-any.whl

Total release size: 197.0 kB

Release files / authwarden-1.1.1.tar.gz

Download URL authwarden-1.1.1.tar.gz
Size 112.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2b2decf42821bf2413ff39b1ab07ee76a23ba005bee2b420d13feb81dfcb5faf
BLAKE2b-256 checksum
How to use checksums
ec30755aa89aa81650d41cfea5098128cc16580d5a54cd13b37a15a99e9915bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / authwarden-1.1.1-py3-none-any.whl

Download URL authwarden-1.1.1-py3-none-any.whl
Size 84.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c971601c221cf33974c34838d4187f1b9c96a42a9a5e7fc24e2d5f00a09ac914
BLAKE2b-256 checksum
How to use checksums
6b290bc5c7c4dd52ca900e2e62a1bc609bcb4e6e44bf81fc0efac8e64c3dea36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Security for authwarden 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for authwarden-1.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page