22 lines
613 B
Python
22 lines
613 B
Python
import os
|
|
from fastapi import Depends, HTTPException, Security
|
|
from fastapi.security import APIKeyHeader
|
|
from starlette.status import HTTP_403_FORBIDDEN
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
API_KEY = os.getenv("IGNIS_API_KEY")
|
|
API_KEY_NAME = "X-API-Key"
|
|
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False)
|
|
|
|
|
|
async def verify_token(header_value: str = Depends(api_key_header)):
|
|
if not API_KEY:
|
|
return None
|
|
if header_value == API_KEY:
|
|
return header_value
|
|
raise HTTPException(
|
|
status_code=HTTP_403_FORBIDDEN, detail="Could not validate credentials"
|
|
)
|