Fix issues

This commit is contained in:
Urtzi Alfaro
2025-07-18 11:51:43 +02:00
parent 9391368b83
commit 592a810762
35 changed files with 3806 additions and 122 deletions

View File

@@ -0,0 +1,36 @@
# ================================================================
# services/data/app/core/auth.py
# ================================================================
"""Authentication utilities for data service"""
from fastapi import HTTPException, Depends, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
import httpx
import structlog
from app.core.config import settings
logger = structlog.get_logger()
security = HTTPBearer()
async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)) -> dict:
"""Verify JWT token with auth service"""
try:
async with httpx.AsyncClient() as client:
response = await client.post(
f"{settings.AUTH_SERVICE_URL}/api/v1/auth/verify",
headers={"Authorization": f"Bearer {credentials.credentials}"}
)
if response.status_code == 200:
return response.json()
else:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid authentication credentials"
)
except httpx.RequestError:
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="Authentication service unavailable"
)