fabian/dev/: users-auth-0.0.1 metadata and description

Simple index

A FastAPI library for user authentication and management

author_email Fabian Aichele <aichele@zykl.io>
description_content_type text/markdown
keywords fastapi, library, domain
project_urls
  • Homepage, https://github.com/faichele/users_auth
  • Repository, https://github.com/faichele/users_auth.git
requires_dist
  • pydantic<3,>=2.7
  • pytest; extra == "dev"
  • pytest-cov; extra == "dev"
  • mypy; extra == "dev"
  • ruff; extra == "dev"
  • build; extra == "dev"
  • twine; extra == "dev"
requires_python >=3.9

Because this project isn't in the mirror_whitelist, no releases from root/pypi are included.

File Tox results History
users_auth-0.0.1-py3-none-any.whl
Size
4 KB
Type
Python Wheel
Python
3
  • Replaced 6 time(s)
  • Uploaded to fabian/dev by fabian 2026-01-09 20:58:54
users_auth-0.0.1.tar.gz
Size
4 KB
Type
Source
  • Replaced 6 time(s)
  • Uploaded to fabian/dev by fabian 2026-01-09 20:58:56

Users Auth Module

Ein wiederverwendbares Python-Modul für Benutzerverwaltung und Authentifizierung in FastAPI-Anwendungen.

Überblick

Das users_auth Modul bietet eine vollständige, produktionsreife Lösung für:

Architektur

Das Modul folgt einer sauberen, schichtweisen Architektur:

users_auth/
├── models/              # Pydantic-Modelle und SQLAlchemy-Entitäten
│   ├── user_models.py   # Benutzer-Datenmodelle
│   └── auth_models.py   # Authentifizierungs-Modelle
├── services/            # Business Logic Layer
│   ├── user_service.py  # Benutzer-Geschäftslogik
│   └── auth_service.py  # Authentifizierungs-Logik
├── utils/               # Utility-Funktionen
│   ├── security.py      # Passwort-Hashing und Sicherheit
│   └── token_utils.py   # JWT-Token-Management
├── dependencies/        # FastAPI Dependencies
│   └── auth_deps.py     # Authentifizierungs-Dependencies
├── routers/             # FastAPI Router
│   ├── auth_router.py   # Authentifizierungs-Endpunkte
│   └── user_router.py   # Benutzer-Endpunkte
└── examples/            # Integrations-Beispiele
    └── integration_example.py

Features

Benutzermodell

Authentifizierung

API-Endpunkte

Authentifizierung (/auth)

Benutzerverwaltung (/users)

Installation & Integration

1. Einfache Integration (empfohlen)

from fastapi import FastAPI
from users_auth import UserAuthModule

app = FastAPI()

# Authentifizierungsmodul integrieren
auth_module = UserAuthModule(app, database_session, config)

2. Manuelle Integration

from users_auth.services import AuthService, UserService
from users_auth.dependencies import AuthDependencies
from users_auth.routers import create_auth_router, create_user_router

# Services erstellen
auth_service = AuthService(db_session, config)
user_service = UserService(db_session)

# Dependencies erstellen
auth_deps = AuthDependencies(auth_service, user_service)

# Router erstellen und einbinden
auth_router = create_auth_router(auth_service, auth_deps)
user_router = create_user_router(user_service, auth_deps)

app.include_router(auth_router)
app.include_router(user_router)

3. Konfiguration

Das Modul benötigt ein Konfigurationsobjekt mit folgenden Attributen:

class Config:
    SECRET_KEY: str                    # JWT-Signierung
    ACCESS_TOKEN_EXPIRE_MINUTES: int  # Token-Gültigkeitsdauer

4. Datenbank-Setup

from users_auth.models.user_models import User

# Tabellen erstellen (oder mit Alembic migrieren)
User.metadata.create_all(bind=engine)

Verwendung in Routern

Dependencies verwenden

from fastapi import APIRouter, Depends
from users_auth.dependencies import CurrentUser, CurrentSuperuser

router = APIRouter()

@router.get("/protected")
def protected_route(current_user: CurrentUser):
    return {"user": current_user.email}

@router.get("/admin-only")
def admin_route(current_user: CurrentSuperuser):
    return {"message": "Admin access"}

Services verwenden

from users_auth.services import UserService, AuthService

def some_business_logic(db_session, config):
    user_service = UserService(db_session)
    auth_service = AuthService(db_session, config)
    
    # Benutzer erstellen
    user = user_service.create_user(user_data)
    
    # Authentifizierung
    token_data = auth_service.login(email, password)

Sicherheitsfeatures

Best Practices

1. Umgebungsvariablen

SECRET_KEY=your-super-secret-key-here
ACCESS_TOKEN_EXPIRE_MINUTES=30

2. Produktions-Setup

3. E-Mail-Integration

Für Passwort-Reset-E-Mails erweitern Sie die AuthService:

def send_password_reset_email(self, email: str, token: str):
    # Ihre E-Mail-Implementierung
    pass

Erweiterbarkeit

Das Modul ist für Erweiterungen konzipiert:

Abhängigkeiten

Beispiel-Integration in Rideto

# In der bestehenden Rideto-App
from backend.app.config import settings
from backend.database.base import get_db
from users_auth import UserAuthModule

def setup_auth(app: FastAPI):
    class AuthConfig:
        SECRET_KEY = settings.SECRET_KEY
        ACCESS_TOKEN_EXPIRE_MINUTES = settings.ACCESS_TOKEN_EXPIRE_MINUTES
    
    auth_module = UserAuthModule()
    auth_module.init_app(app, next(get_db()), AuthConfig())

Dieses Modul bietet eine solide Grundlage für Authentifizierung und Benutzerverwaltung, die in verschiedenen FastAPI-Projekten wiederverwendet werden kann.