setup assisant bot
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
from fastapi import HTTPException, Depends, Security
|
||||
from fastapi.security import APIKeyHeader
|
||||
from api.models.requests import BaseRequest
|
||||
from config import Config
|
||||
|
||||
api_key_header = APIKeyHeader(name="Authorization", auto_error=False)
|
||||
|
||||
async def get_api_key(api_key_header: str = Security(api_key_header)) -> str:
|
||||
"""Validate API key from header"""
|
||||
if not api_key_header or not api_key_header.startswith('Bearer '):
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail={"error": "Unauthorized", "message": "API key is missing or invalid."}
|
||||
)
|
||||
|
||||
token = api_key_header.split(' ')[1]
|
||||
|
||||
if token != Config.API_KEY:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail={"error": "Unauthorized", "message": "API key does not match."}
|
||||
)
|
||||
|
||||
return token
|
||||
|
||||
Reference in New Issue
Block a user