Industry-standard session-based authentication for FastAPI with secure cookies
Project description
IA Auth Sessions
Standard session-based authentication for FastAPI applications using secure signed cookies.
Features
- Signed Cookies: HMAC-SHA256 via
itsdangerousprevents tampering - Bcrypt Password Hashing: Industry standard with automatic salt generation via
pwdlib - Python 3.13+ Ready: Uses modern
pwdlibinstead of deprecatedpasslib - Secure Cookie Flags: HttpOnly, Secure, SameSite protection
- Session Management: Create, validate, destroy, and auto-cleanup
- Database Agnostic: PostgreSQL and SQLite via NexusQL
- WebSocket Support: Authenticate WebSocket connections
Available Routes
POST /auth/register- Register new userPOST /auth/login- Login and create sessionPOST /auth/logout- Logout and destroy sessionGET /auth/me- Get current user infoPOST /auth/logout-all- Logout from all devices
Installation
pip install ia-auth-sessions
For local development:
pip install -e ../ia_auth_sessions
Publishing
See PUBLISHING.md for instructions on publishing to PyPI.
To test the build locally:
python test_publish.py --skip-tests
Quick Start
from fastapi import FastAPI, Depends
from ia_auth_sessions import SessionMiddleware, get_current_user
from ia_auth_sessions.routes import router as auth_router
app = FastAPI()
# Add middleware and routes
app.add_middleware(SessionMiddleware, secret_key="your-secret-key", ...)
app.include_router(auth_router)
# Protected route
@app.get("/protected")
async def protected(user: dict = Depends(get_current_user)):
return {"message": f"Hello {user['username']}!"}
See USAGE.md for complete setup instructions.
Documentation
- USAGE.md - Complete setup guide, examples, and API reference
- ARCHITECTURE_NOTES.md - Design decisions and architecture
Database Schema
Automatically creates:
users: User accounts with bcrypt-hashed passwordssessions: Active sessions with metadata and expiry timestamps
License
MIT
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 ia_auth_sessions-0.1.0.tar.gz.
File metadata
- Download URL: ia_auth_sessions-0.1.0.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5c2f1dbb909dc45b3416a69939b314fab503de28713f5918ce27469cd30abe2
|
|
| MD5 |
7e2665f5e59fa9081f14d10f0aebe056
|
|
| BLAKE2b-256 |
64bfa04f368e2adcac8849684e758b84f92df226cab9534288b21686c43a9b3f
|
File details
Details for the file ia_auth_sessions-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ia_auth_sessions-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2600d734376a7508b29e4c257776c2762cc5b991a33adb78aa5fb429b3fec93b
|
|
| MD5 |
e13999634bd43b87d5751842448473ab
|
|
| BLAKE2b-256 |
62b964307b7726f92b0581fff3fa808ba7d5029bfc39e718093c17738b83079b
|