Skip to main content

Advanced authentication library for FastAPI with JWT and MFA support

Project description

Genovation Advanced Auth

PyPI version Python versions License: MIT

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 user
  • POST /auth/login - Login and get JWT token
  • POST /auth/refresh - Refresh access token

MFA

  • POST /auth/mfa/setup - Setup MFA (returns QR code)
  • POST /auth/mfa/verify - Verify and enable MFA
  • POST /auth/mfa/disable - Disable MFA

User Management

  • GET /users/me - Get current user profile
  • PUT /users/me - Update user profile
  • POST /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


Version: 0.1.0
Status: Alpha - Under Active Development

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

genovation_advanced_auth-0.1.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

genovation_advanced_auth-0.1.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

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

Hashes for genovation_advanced_auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 86f481acb668d2ce708f1db9c26c46c971e291d78077df579536bb05359ff770
MD5 c6f624c0dc8c510baf0f723c3801bc2c
BLAKE2b-256 755c72dfe8af14e2421cc6cc430ed734517d0b727126988593c4dcc797b73224

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genovation_advanced_auth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8921272857ead4c17d0ef40786547f9482b4c736be37c449f76f4afd001383d7
MD5 9848465c0651d060e32b529645f1fc1b
BLAKE2b-256 8e99c60e5f1c822aec7e15fc4075eafd7886bb8cfc807564ddbc8e12e29643f8

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