Skip to main content

Comprehensive authentication and authorization library for Python

Project description

authfort

Complete authentication and authorization library for Python.

Install

pip install authfort[fastapi]
# or with SQLite: pip install authfort[sqlite,fastapi]

Quick Start

from authfort import AuthFort, CookieConfig
from fastapi import FastAPI, Depends

auth = AuthFort(
    database_url="postgresql+asyncpg://user:pass@localhost/mydb",
    cookie=CookieConfig(),
)

app = FastAPI()
app.include_router(auth.fastapi_router(), prefix="/auth")
app.include_router(auth.jwks_router())

@app.get("/profile")
async def profile(user=Depends(auth.current_user)):
    return {"email": user.email, "roles": user.roles}

Endpoints

Method Path Description
POST /auth/signup Create account
POST /auth/login Sign in
POST /auth/refresh Refresh access token
POST /auth/logout Sign out
GET /auth/me Get current user
GET /auth/oauth/{provider}/authorize Start OAuth flow
GET /auth/oauth/{provider}/callback OAuth callback
POST /auth/introspect Token introspection
GET /.well-known/jwks.json Public signing keys

Features

  • Email/password auth with argon2 hashing
  • JWT RS256 with automatic key management
  • Refresh token rotation with theft detection
  • OAuth 2.1 with PKCE (Google, GitHub)
  • Role-based access control
  • Session management (list, revoke)
  • Ban/unban users
  • Event hooks
  • JWKS + key rotation
  • Cookie and bearer token modes
  • Multi-database: PostgreSQL (default), SQLite, MySQL

OAuth

from authfort import AuthFort, GoogleProvider, GitHubProvider

auth = AuthFort(
    database_url="...",
    providers=[
        GoogleProvider(client_id="...", client_secret="..."),
        GitHubProvider(client_id="...", client_secret="..."),
    ],
)

Programmatic API

# Create users without the HTTP endpoint
result = await auth.create_user("admin@example.com", "password", name="Admin")

# Roles
await auth.add_role(user_id, "admin")
await auth.remove_role(user_id, "editor")

# Sessions
sessions = await auth.get_sessions(user_id, active_only=True)
await auth.revoke_session(session_id)

# Ban/unban
await auth.ban_user(user_id)
await auth.unban_user(user_id)

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

authfort-0.0.2.tar.gz (41.5 kB view details)

Uploaded Source

Built Distribution

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

authfort-0.0.2-py3-none-any.whl (42.7 kB view details)

Uploaded Python 3

File details

Details for the file authfort-0.0.2.tar.gz.

File metadata

  • Download URL: authfort-0.0.2.tar.gz
  • Upload date:
  • Size: 41.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for authfort-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a6691b3cb90024b620816e958e7dbb0085be69e59b8d9bea7dae747992850c4a
MD5 9844f3a4d70158526dfb6e5f35a9f2fe
BLAKE2b-256 1c3a439aa8e9e2ca3e689cf400570ead6e026683a71e52dfd431f40704c2d7ac

See more details on using hashes here.

File details

Details for the file authfort-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: authfort-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 42.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for authfort-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b344c62c9b39cc93965afa6b5e28b1aaaa9200c1b12db58622dedd191f34ad98
MD5 cbc6cbf60f191bdc71f9702206b752ae
BLAKE2b-256 cc6ae9e75a15daefdd7a712cf65306d931ae4e1e30a84ccc78738f05349acaae

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