Production-ready authentication for FastAPI applications
Project description
FastAuth
Production-ready authentication for FastAPI applications
FastAuth is a flexible, database-agnostic authentication library for FastAPI that provides secure user authentication, session management, and authorization out of the box.
โจ Features
- Complete Authentication - Registration, login, logout, token refresh
- Role-Based Access Control - Fine-grained permissions and roles
- Session Management - Multi-device session tracking
- OAuth Support - Social login (Google, GitHub, etc.)
- Email Verification - Secure email verification with tokens
- Password Reset - Self-service password reset
- Database Agnostic - Works with any database via adapters
- Type Safe - Full type hints and validation
๐ Quick Start
Install
pip install sreekarnv-fastauth
Create Your App
from fastapi import Depends, FastAPI
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from fastauth.api.auth import router as auth_router
from fastauth.security.jwt import decode_access_token
app = FastAPI()
app.include_router(auth_router)
security = HTTPBearer()
@app.get("/protected")
def protected(credentials: HTTPAuthorizationCredentials = Depends(security)):
payload = decode_access_token(credentials.credentials)
return {"user_id": payload["sub"]}
Run
uvicorn main:app --reload
Visit http://localhost:8000/docs to see the auto-generated API documentation.
๐ Documentation
- Getting Started - Install and setup in 5 minutes
- Guides - Authentication, RBAC, sessions, OAuth
- API Reference - Complete API documentation
- Examples - Working example applications
๐ก Examples
Check out complete working examples:
- OAuth with Google - Social login with PKCE
- RBAC Blog - Role-based access control
- Session Management - Multi-device tracking
- Basic App - Simple authentication
๐ Security
FastAuth follows security best practices:
- โ Argon2 password hashing (OWASP recommended)
- โ JWT tokens with configurable expiration
- โ Rate limiting for authentication endpoints
- โ Refresh token rotation
- โ Session tracking and revocation
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your FastAPI App โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ FastAuth API Layer โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Core Business Logic โ โ Database-agnostic
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Adapter Interface โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Database Implementation โ โ SQLAlchemy, MongoDB, etc.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Key Principles:
- Database-agnostic core
- Adapter pattern for flexibility
- Dependency injection
- Full type safety
๐ค Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
# Setup development environment
git clone https://github.com/sreekarnv/fastauth.git
cd fastauth
poetry install
poetry run pytest
๐ License
MIT License - see LICENSE for details.
๐ Acknowledgments
Built with FastAPI, SQLModel, Argon2, and python-jose.
โญ Star this repo if you find it useful!
Made with โค๏ธ by Sreekar Nutulapati
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sreekarnv_fastauth-0.2.2.tar.gz.
File metadata
- Download URL: sreekarnv_fastauth-0.2.2.tar.gz
- Upload date:
- Size: 26.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.2 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91d0f6c4a66ad310331bb7049afd1b45b714b00655d66fa3a50e82004ab838b7
|
|
| MD5 |
67bef7f36043872125ed76596a56712d
|
|
| BLAKE2b-256 |
6c1d6c595219b271035ef351ac3ba1d8c35eee156d64cf1fd3465808f392da1b
|
File details
Details for the file sreekarnv_fastauth-0.2.2-py3-none-any.whl.
File metadata
- Download URL: sreekarnv_fastauth-0.2.2-py3-none-any.whl
- Upload date:
- Size: 47.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.2 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2427689b72b300282342a091fc791937643299e001cc073a9481042f04876362
|
|
| MD5 |
60b5ba6f6de39214f7b5fa5f0f044427
|
|
| BLAKE2b-256 |
02280b1525919901060b195e1bb0f0bb3c20939f16945607c17c91ba30de580f
|