Advanced authentication library for FastAPI with JWT and MFA support
Project description
Genovation Advanced Auth
A comprehensive FastAPI authentication library with JWT and Multi-Factor Authentication (MFA) support.
Features
- ✅ User Registration & Login - Secure user authentication
- ✅ JWT Tokens - Token-based authentication with automatic refresh
- ✅ Multi-Factor Authentication (MFA) - TOTP-based 2FA with Google Authenticator support
- ✅ Backup Codes - Recovery codes for MFA
- ✅ Password Security - Bcrypt hashing with configurable rounds
- ✅ QR Code Generation - For easy authenticator app setup
- ✅ Type Safe - Full type hints and Pydantic validation
- ✅ Production Ready - Security best practices built-in
Installation
pip install genovation-advanced-auth
With SQLAlchemy support:
pip install genovation-advanced-auth[sqlalchemy]
Quick Start
Create .env file:
AUTH_SECRET_KEY=your-super-secret-key-here
AUTH_MFA_ISSUER_NAME=MyCompany
AUTH_ACCESS_TOKEN_EXPIRE_MINUTES=30
The library auto-loads these settings.
Advanced Configuration
Override settings in code: from genovation_advanced_auth.core.config import AuthConfig, set_config
config = AuthConfig( secret_key="your-secret", mfa_issuer_name="MyApp", mfa_backup_codes_count=15 ) set_config(config)
Available Settings
| Setting | Environment Variable | Default | Description |
|---|---|---|---|
secret_key |
AUTH_SECRET_KEY |
Required | JWT signing key |
algorithm |
AUTH_ALGORITHM |
HS256 |
JWT algorithm |
access_token_expire_minutes |
AUTH_ACCESS_TOKEN_EXPIRE_MINUTES |
30 |
Token lifetime |
mfa_issuer_name |
AUTH_MFA_ISSUER_NAME |
MyApp |
Shown in authenticator apps |
mfa_backup_codes_count |
AUTH_MFA_BACKUP_CODES_COUNT |
10 |
Number of backup codes |
Basic Setup
from fastapi import FastAPI, Depends from genovation_advanced_auth import AuthRouter, UsersRouter, get_current_user
app = FastAPI() Include authentication routes
app.include_router(AuthRouter, prefix="/api/v1/auth", tags=["authentication"]) app.include_router(UsersRouter, prefix="/api/v1/users", tags=["users"]) Protected endpoint example
@app.get("/protected") async def protected_route(current_user = Depends(get_current_user)): return {"message": f"Hello {current_user['username']}!"}
Configuration
from genovation_advanced_auth import AuthConfig
config = AuthConfig( secret_key="your-secret-key-here", algorithm="HS256", access_token_expire_minutes=30, mfa_issuer_name="YourApp" )
API Endpoints
Authentication
POST /auth/register- Register new userPOST /auth/login- Login and get JWT tokenPOST /auth/refresh- Refresh access token
MFA
POST /auth/mfa/setup- Setup MFA (returns QR code)POST /auth/mfa/verify- Verify and enable MFAPOST /auth/mfa/disable- Disable MFA
User Management
GET /users/me- Get current user profilePUT /users/me- Update user profilePOST /users/change-password- Change password
Documentation
Full documentation is available in the docs directory.
Development
Clone repository
git clone https://github.com/genovation/genovation-advanced-auth.git cd genovation-advanced-auth Install with dev dependencies
pip install -e ".[dev]" Run tests
pytest Run with coverage
pytest --cov=genovation_advanced_auth
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- 📧 Email: Connect@genovationsolutions.com
- 🐛 Issues: GitHub Issues
Version: 0.1.0
Status: Alpha - Under Active Development
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 genovation_advanced_auth-0.1.0.tar.gz.
File metadata
- Download URL: genovation_advanced_auth-0.1.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86f481acb668d2ce708f1db9c26c46c971e291d78077df579536bb05359ff770
|
|
| MD5 |
c6f624c0dc8c510baf0f723c3801bc2c
|
|
| BLAKE2b-256 |
755c72dfe8af14e2421cc6cc430ed734517d0b727126988593c4dcc797b73224
|
File details
Details for the file genovation_advanced_auth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: genovation_advanced_auth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.3 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 |
8921272857ead4c17d0ef40786547f9482b4c736be37c449f76f4afd001383d7
|
|
| MD5 |
9848465c0651d060e32b529645f1fc1b
|
|
| BLAKE2b-256 |
8e99c60e5f1c822aec7e15fc4075eafd7886bb8cfc807564ddbc8e12e29643f8
|