Spaces:
Paused
Paused
Upload 2 files
Browse files- app/core/auth.py +17 -0
- app/core/config.py +3 -0
app/core/auth.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import Depends, HTTPException, status, Header
|
| 2 |
+
from typing import Optional
|
| 3 |
+
from .config import settings
|
| 4 |
+
|
| 5 |
+
async def verify_service_token(
|
| 6 |
+
x_service_token: Optional[str] = Header(None, alias="X-Service-Token")
|
| 7 |
+
) -> None:
|
| 8 |
+
if not x_service_token:
|
| 9 |
+
raise HTTPException(
|
| 10 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 11 |
+
detail="X-Service-Token header is missing",
|
| 12 |
+
)
|
| 13 |
+
if x_service_token != settings.SERVICE_TOKEN:
|
| 14 |
+
raise HTTPException(
|
| 15 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 16 |
+
detail="Invalid service token",
|
| 17 |
+
)
|
app/core/config.py
CHANGED
|
@@ -7,6 +7,9 @@ class Settings(BaseSettings):
|
|
| 7 |
PROJECT_NAME: str = "Admin Dashboard"
|
| 8 |
VERSION: str = "1.0.0"
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
# PostgreSQL Database settings
|
| 11 |
DATABASE_URL: ClassVar[str] = "postgresql+asyncpg://postgres.juycnkjuzylnbruwaqmp:Lovyelias5584.@aws-0-eu-central-1.pooler.supabase.com:5432/postgres"
|
| 12 |
|
|
|
|
| 7 |
PROJECT_NAME: str = "Admin Dashboard"
|
| 8 |
VERSION: str = "1.0.0"
|
| 9 |
|
| 10 |
+
# Service Authentication
|
| 11 |
+
SERVICE_TOKEN: str = "6f9aee88d5b94b0190c317abcbf4e6e7834cc2c7f02e45693e123456789abcde"
|
| 12 |
+
|
| 13 |
# PostgreSQL Database settings
|
| 14 |
DATABASE_URL: ClassVar[str] = "postgresql+asyncpg://postgres.juycnkjuzylnbruwaqmp:Lovyelias5584.@aws-0-eu-central-1.pooler.supabase.com:5432/postgres"
|
| 15 |
|