926d0fa272
Tests / test (push) Failing after 0s
Tests / lint (push) Failing after 0s
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""
|
|
Authentication dependency compatibility layer.
|
|
|
|
Canonical bearer-token parsing lives in app.auth. This module remains only so
|
|
legacy imports have a safe target while workspace dependencies are rebuilt.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from app.auth import AuthenticatedUser
|
|
from app.auth import get_current_user as get_authenticated_user
|
|
from app.dependencies import get_user_repository
|
|
from fastapi import Depends
|
|
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
|
|
|
from packages.domain.entities import User
|
|
from packages.ports.user_repository import UserRepository
|
|
|
|
optional_bearer_scheme = HTTPBearer(auto_error=False)
|
|
|
|
|
|
async def get_current_user(
|
|
authenticated_user: AuthenticatedUser = Depends(get_authenticated_user),
|
|
) -> User:
|
|
return authenticated_user.user
|
|
|
|
|
|
async def get_current_user_optional(
|
|
credentials: HTTPAuthorizationCredentials | None = Depends(optional_bearer_scheme),
|
|
user_repository: UserRepository = Depends(get_user_repository),
|
|
) -> User | None:
|
|
if credentials is None:
|
|
return None
|
|
try:
|
|
authenticated_user = await get_authenticated_user(credentials, user_repository)
|
|
except HTTPException:
|
|
return None
|
|
return authenticated_user.user
|