03c3b18565
Port RFC-001 authentication core from PR #1728: - JWT token handling (create_access_token, decode_token, TokenPayload) - Password hashing (bcrypt) with verify_password - SQLite UserRepository with base interface - Provider Factory pattern (LocalAuthProvider) - CLI reset_admin tool - Auth-specific errors (AuthErrorCode, TokenError, AuthErrorResponse) Deps: - bcrypt>=4.0.0 - pyjwt>=2.9.0 - email-validator>=2.0.0 - backend/uv.toml pins public PyPI index Tests: 12 pure unit tests (test_auth_config.py, test_auth_errors.py). Scope note: authz.py, test_auth.py, and test_auth_type_system.py are deferred to commit 2 because they depend on middleware and deps wiring that is not yet in place. Commit 1 stays "pure new files only" as the spec mandates.
25 lines
628 B
Python
25 lines
628 B
Python
"""Auth provider abstraction."""
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
|
class AuthProvider(ABC):
|
|
"""Abstract base class for authentication providers."""
|
|
|
|
@abstractmethod
|
|
async def authenticate(self, credentials: dict) -> "User | None":
|
|
"""Authenticate user with given credentials.
|
|
|
|
Returns User if authentication succeeds, None otherwise.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
async def get_user(self, user_id: str) -> "User | None":
|
|
"""Retrieve user by ID."""
|
|
...
|
|
|
|
|
|
# Import User at runtime to avoid circular imports
|
|
from app.gateway.auth.models import User # noqa: E402
|