Files
xiaoxia-saas/apps/api/app/middleware/auth.py
T
xiaoxia 6efdfbe194
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Successful in 42s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 1m13s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 1m19s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 1m19s
CI/CD Pipeline / Build Staging API Image (push) Failing after 1m33s
CI/CD Pipeline / Build Staging Worker Image (push) Failing after 1m6s
CI/CD Pipeline / Build Production API Image (push) Failing after 50s
CI/CD Pipeline / Frontend Unit Tests (push) Failing after 1m10s
CI/CD Pipeline / Build Production Web Image (push) Failing after 16s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 16s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Validate - Code Quality (push) Successful in 4m50s
CI/CD Pipeline / Staging E2E Tests (push) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (push) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Canary Release to Production (push) Has been skipped
CI/CD Pipeline / Unit Tests (push) Successful in 5m38s
CI/CD Pipeline / Integration Tests (push) Successful in 4m56s
CI/CD Pipeline / CI Gate (push) Has been skipped
fix(ci): pyproject.toml添加原生ruff配置,修复Code Quality全量检查失败 (#1074)
2026-07-28 13:19:55 +08:00

39 lines
1.2 KiB
Python

"""
Authentication dependency compatibility layer.
Canonical bearer-token parsing lives in app.auth. This module re-exports
common auth dependencies for backward compatibility.
"""
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, HTTPException
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