Add authentication features for admin access
- Introduce a new `auth` module with login, logout, and user verification endpoints for a single admin user. - Update backend routes to require admin authentication for sensitive operations, enhancing security. - Modify frontend components to include an authentication provider and gate, ensuring only authorized users can access the application. - Implement a login page for admin access, improving user experience and security management. - Update API request handling to redirect unauthorized users to the login page, ensuring proper access control.
This commit is contained in:
@@ -11,9 +11,10 @@
|
||||
import asyncio
|
||||
|
||||
from db.session import SessionLocal
|
||||
from fastapi import APIRouter, WebSocket
|
||||
from fastapi import APIRouter, Depends, WebSocket
|
||||
from loguru import logger
|
||||
from models import AssistantConfig, SignalingOffer
|
||||
from services.auth import require_admin, require_admin_websocket
|
||||
from services.config_resolver import resolve_runtime_config
|
||||
from starlette.websockets import WebSocketDisconnect, WebSocketState
|
||||
|
||||
@@ -24,7 +25,7 @@ from services.webrtc_ice import aiortc_ice_servers, client_ice_servers
|
||||
router = APIRouter(tags=["voice"])
|
||||
|
||||
|
||||
@router.get("/api/webrtc/ice-servers")
|
||||
@router.get("/api/webrtc/ice-servers", dependencies=[Depends(require_admin)])
|
||||
async def ice_servers():
|
||||
"""Browser fetches STUN/TURN config (with ephemeral TURN creds when configured)."""
|
||||
return {"iceServers": client_ice_servers()}
|
||||
@@ -32,6 +33,8 @@ async def ice_servers():
|
||||
|
||||
@router.websocket("/ws/voice")
|
||||
async def voice_signaling(websocket: WebSocket):
|
||||
if not await require_admin_websocket(websocket):
|
||||
return
|
||||
await websocket.accept()
|
||||
peers: dict = {}
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user