Skip to main content

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 itsdangerous prevents tampering
  • Bcrypt Password Hashing: Industry standard with automatic salt generation via pwdlib
  • Python 3.13+ Ready: Uses modern pwdlib instead of deprecated passlib
  • 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 user
  • POST /auth/login - Login and create session
  • POST /auth/logout - Logout and destroy session
  • GET /auth/me - Get current user info
  • POST /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

Database Schema

Automatically creates:

  • users: User accounts with bcrypt-hashed passwords
  • sessions: Active sessions with metadata and expiry timestamps

License

MIT

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

ia_auth_sessions-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

ia_auth_sessions-0.1.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

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

Hashes for ia_auth_sessions-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a5c2f1dbb909dc45b3416a69939b314fab503de28713f5918ce27469cd30abe2
MD5 7e2665f5e59fa9081f14d10f0aebe056
BLAKE2b-256 64bfa04f368e2adcac8849684e758b84f92df226cab9534288b21686c43a9b3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ia_auth_sessions-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2600d734376a7508b29e4c257776c2762cc5b991a33adb78aa5fb429b3fec93b
MD5 e13999634bd43b87d5751842448473ab
BLAKE2b-256 62b964307b7726f92b0581fff3fa808ba7d5029bfc39e718093c17738b83079b

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