Skip to main content

A reusable FastAPI authentication module with JWT, Google OAuth, rate limiting and brute-force protection

Project description

auth-kit

A reusable FastAPI authentication module. Install via pip and add to any FastAPI project in minutes.

Features

  • JWT access tokens (15 min) + refresh tokens (7 days) with rotation
  • Google OAuth2 via authlib
  • Redis-backed per-IP rate limiting (60 req/min)
  • Brute-force protection — exponential backoff after 5 failed logins
  • Async SQLAlchemy + Alembic migrations
  • 90%+ test coverage

Installation

pip install auth-kit

Quick start (standalone server)

1. Start infrastructure

docker compose up -d

2. Configure environment

cp .env.example .env
# Fill in SECRET_KEY, DATABASE_URL, REDIS_URL
# Optionally: GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET

3. Run migrations

alembic upgrade head

4. Start the server

uvicorn auth_kit.main:app --reload

Visit http://localhost:8000/docs for the interactive API.

Plugging into an existing FastAPI project

from fastapi import FastAPI
from auth_kit.api.auth import router as auth_router
from auth_kit.api.users import router as users_router
from auth_kit.middleware.rate_limit import RateLimitMiddleware
from auth_kit.settings import settings

app = FastAPI()

app.add_middleware(RateLimitMiddleware)
app.include_router(auth_router)
app.include_router(users_router)

Endpoints

Method Path Auth Description
POST /auth/register Create account
POST /auth/login Get token pair
POST /auth/refresh Rotate tokens
POST /auth/logout Invalidate refresh token
GET /auth/google Start Google SSO
GET /auth/google/callback Google SSO callback
GET /users/me Get profile
PUT /users/me Update profile
GET /health DB + Redis health check

Running tests

pytest --cov=auth_kit --cov-report=term-missing

Environment variables

Variable Description Default
DATABASE_URL Postgres async URL required
REDIS_URL Redis URL required
SECRET_KEY JWT signing key (min 32 chars) required
ALGORITHM JWT algorithm HS256
ACCESS_TOKEN_EXPIRE_MINUTES Access token TTL 15
REFRESH_TOKEN_EXPIRE_DAYS Refresh token TTL 7
ALLOWED_ORIGINS CORS origins ["*"]
DEBUG Enable SQL query logging false
GOOGLE_CLIENT_ID Google OAuth client ID ""
GOOGLE_CLIENT_SECRET Google OAuth client secret ""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_auth_bundle-0.1.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_auth_bundle-0.1.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_auth_bundle-0.1.0.tar.gz.

File metadata

  • Download URL: fastapi_auth_bundle-0.1.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fastapi_auth_bundle-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf9d7a0ced6fff3fef09870d156fc339deebc486517769954402f5c0e15a6b1a
MD5 d3e2b196a128f365c7b2a7887d22fc16
BLAKE2b-256 cdd1eace00b9c9ec4a73e34122a2463ae237ec1da01dd853dc3fe81446e9385e

See more details on using hashes here.

File details

Details for the file fastapi_auth_bundle-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_auth_bundle-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b356fe3c78948d09405d6b6cd4ab7dc8a2f6311732a2983cd33db515e11b8d57
MD5 681d721d6dcc8acd10c02239ce4219fe
BLAKE2b-256 9075d95aa85b734f29c21ad78114ca7d9f6156876aa3fa375076669cc439bb8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page