🔐 Auth: інтеграція JWT в Memory Service + конфігурації
- Опціональна JWT auth в Memory Service endpoints - get_current_service_optional для backward compatibility - NATS auth config (nkeys) - шаблони - Qdrant auth config (API keys) - шаблони - Тестовий скрипт для повного потоку TODO: Генерація реальних JWT/ключів та застосування конфігів
This commit is contained in:
@@ -5,7 +5,7 @@ JWT Authentication для Memory Service
|
||||
import os
|
||||
import jwt
|
||||
import time
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
from fastapi import HTTPException, Security
|
||||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||
from app.config import get_settings
|
||||
@@ -42,8 +42,21 @@ def verify_jwt_token(token: str) -> dict:
|
||||
raise HTTPException(status_code=401, detail="Invalid token")
|
||||
|
||||
|
||||
async def get_current_service_optional(
|
||||
credentials: Optional[HTTPAuthorizationCredentials] = Security(security, auto_error=False)
|
||||
) -> Optional[dict]:
|
||||
"""Dependency для отримання поточного сервісу з JWT (опціонально)"""
|
||||
if not credentials:
|
||||
return None
|
||||
token = credentials.credentials
|
||||
try:
|
||||
payload = verify_jwt_token(token)
|
||||
return payload
|
||||
except HTTPException:
|
||||
return None
|
||||
|
||||
async def get_current_service(credentials: HTTPAuthorizationCredentials = Security(security)) -> dict:
|
||||
"""Dependency для отримання поточного сервісу з JWT"""
|
||||
"""Dependency для отримання поточного сервісу з JWT (обов'язково)"""
|
||||
token = credentials.credentials
|
||||
payload = verify_jwt_token(token)
|
||||
return payload
|
||||
|
||||
Reference in New Issue
Block a user