Professional, secure modern authorization and authentication system.
Project description
ZenithAuth 🛡️
ZenithAuth is a professional-grade, high-performance, and secure authentication and authorization library for modern Python applications. It combines the speed of stateless JWTs with the security of stateful Redis-backed revocation.
✨ Key Features
- Secure Hashing: Powered by Argon2id, the industry winner of the Password Hashing Competition.
- Hybrid Auth Engine: Stateless JWTs for speed, paired with a Redis-backed blacklist for instant token revocation (logouts).
- Modern Data Validation: Built on Pydantic V2 for strict type safety and performance.
- MFA (Multi-Factor Auth): Out-of-the-box support for TOTP (Google Authenticator) with built-in QR code generation.
- Fine-Grained Authorization: Role-Based Access Control (RBAC) and scoped permissions support.
- FastAPI Native: Includes first-class Dependency Injection helpers for FastAPI and Starlette.
- Agnostic Storage: Works with any database (SQLAlchemy, Tortoise, MongoDB) via the Repository Protocol.
🚀 Installation
pip install zenithauth
🛠️ Quick Start (FastAPI)
ZenithAuth makes protecting your API endpoints intuitive.
from fastapi import FastAPI, Depends
from zenithauth.manager import ZenithAuth
from zenithauth.integrations.fastapi import ZenithAuthFastAPI
app = FastAPI()
# 1. Initialize the library
# Ensure ZENITH_SECRET_KEY and ZENITH_REDIS_URL are in your .env
auth_manager = ZenithAuth()
zenith = ZenithAuthFastAPI(auth_manager)
@app.post("/login")
async def login(email: str, password: str):
# This handles hashing verification and token generation
result = await auth_manager.authenticate(email, password)
return result
@app.get("/secure-data")
async def get_data(user: dict = Depends(zenith.get_current_user)):
return {"message": f"Hello {user['sub']}, you are authorized!"}
@app.get("/admin-only")
async def admin_portal(user: dict = Depends(zenith.require_role("admin"))):
return {"message": "Welcome, Administrator."}
🔐 Multi-Factor Authentication (MFA)
Implementing MFA is a two-step flow in ZenithAuth:
1. Enrollment
# Generate secret and QR code for the user to scan
setup_data = await auth.mfa_enroll_setup(user_id="123", email="user@example.com")
# setup_data contains: {"secret": "...", "qr_code_base64": "..."}
2. Verification
# Finalize the login using the 6-digit TOTP code
tokens = await auth.verify_mfa_and_login(user_id="123", code="123456")
🏗️ Architecture
ZenithAuth follows a Security-by-Default philosophy:
- Stateless JWTs: Tokens carry user identity and roles, reducing database hits.
- JTI Tracking: Every token has a unique ID (JTI).
- Redis Guard: Upon logout, the JTI is blacklisted in Redis until its natural expiry time, preventing "ghost sessions."
- Entropy-Based Passwords: We enforce password strength based on character diversity, not just simple length.
📝 Configuration
ZenithAuth is configured via environment variables for easy deployment:
| Variable | Description | Default |
|---|---|---|
ZENITH_SECRET_KEY |
Secret for JWT signing | REQUIRED |
ZENITH_REDIS_URL |
Redis connection string | redis://localhost:6379/0 |
ZENITH_ALGORITHM |
JWT Algorithm | HS256 |
ZENITH_MIN_PASSWORD_LENGTH |
Minimum length | 12 |
📜 License
Distributed under the MIT License. See LICENSE for more information.
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 zenithauth-0.1.0.tar.gz.
File metadata
- Download URL: zenithauth-0.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94493acc6f70e33f8f741c13a27e27a378b33a8ffe77b1babb9951b3390ceb66
|
|
| MD5 |
5b105ee9f322ef3dd3b0bbd4af37c2c6
|
|
| BLAKE2b-256 |
5dfaa0b9ff1f8238d120543fd07dc62de37d5002b65e40d6065731ae83520dd9
|
File details
Details for the file zenithauth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: zenithauth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f880617cb5a784eafba93576254a7eb361ff24af2c4218ccf9d545f68ba96965
|
|
| MD5 |
99abc1876a9bc11071908db5d7056d2a
|
|
| BLAKE2b-256 |
0e6ea742fa96147a848c91491db4332eef711f01d6f555c296dba882579fd23e
|