File size: 775 Bytes
553fbf7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
MINDI 1.5 Vision-Coder — Auth Middleware

API key validation for production deployment.
"""

from __future__ import annotations

import os
from typing import Optional

from fastapi import HTTPException, Security
from fastapi.security import APIKeyHeader

API_KEY_HEADER = APIKeyHeader(name="X-API-Key", auto_error=False)


async def verify_api_key(
    api_key: Optional[str] = Security(API_KEY_HEADER),
) -> str:
    """Validate the API key from request headers."""
    expected_key = os.environ.get("MINDI_API_KEY", "")

    # In development, skip auth if no key is configured
    if not expected_key:
        return "dev-mode"

    if not api_key or api_key != expected_key:
        raise HTTPException(status_code=403, detail="Invalid API key")

    return api_key