Production-ready authentication system for FastAPI with async support, JWT, refresh tokens, and pluggable database backends.
-
⚡ Fully async (no blocking I/O)
-
🔐 JWT authentication (access + refresh tokens)
-
🔁 Refresh token flow
-
🚪 Logout with token blacklist
-
🧱 Multi-database support:
- PostgreSQL (asyncpg)
- MySQL (aiomysql)
- SQLite (aiosqlite)
- MongoDB (motor)
-
🧠 Dependency-based auth (FastAPI native)
-
📦 Plug-and-play integration
-
🛡️ Password hashing with Argon2 (modern standard)
-
📄 Clean OpenAPI (Swagger) docs with Pydantic schemas
pip install "fastapi-async-auth-kit[<db>]"pip install "fastapi-async-auth-kit[postgres]"
pip install "fastapi-async-auth-kit[mysql]"
pip install "fastapi-async-auth-kit[mongodb]"
pip install "fastapi-async-auth-kit[sqlite]"from fastapi import FastAPI
from fastapi_async_auth_kit import init_auth, AuthConfig
app = FastAPI()
@app.on_event("startup")
async def startup():
await init_auth(
app,
AuthConfig(
secret_key="your-secret",
db_url="postgresql+asyncpg://user:pass@localhost/db",
db_type="postgres"
)
)from fastapi import APIRouter, Depends
from fastapi_async_auth_kit.dependencies.auth import get_current_user
router = APIRouter()
@router.get("/user")
async def me(user=Depends(get_current_user)):
return user| Endpoint | Description |
|---|---|
| POST /auth/register | Register new user |
| POST /auth/login | Login and get tokens |
| POST /auth/refresh | Refresh access token |
| POST /auth/logout | Logout and revoke token |
| GET /auth/me | Get current user |
POST /auth/login
{
"username": "john",
"password": "Strong@123"
}{
"access": "jwt_token",
"refresh": "refresh_token"
}FastAPI App
↓
Auth Service
↓
Repository Layer
↓
Database (Async)
- Argon2 password hashing
- JWT token expiration
- Refresh token blacklist
- No sensitive data exposure
- Clean error handling
- Add RBAC (roles & permissions)
- Plug custom user models
- Add OAuth providers (Google, GitHub)
- Integrate Redis for token storage
- FastAPI
- SQLAlchemy (async)
- Pydantic
- python-jose (JWT)
- Argon2 (password hashing)
- RBAC support
- Redis token blacklist
- OAuth integration
- Rate limiting
- Email verification
Pull requests are welcome. For major changes, open an issue first.
Source Code: https://github.com/kmistry1110/fastapi_auth
MIT License
