File size: 604 Bytes
270736b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from fastapi import Depends, HTTPException, status
from fastapi.security import APIKeyHeader

API_KEYS = ['Fo0nxlisbbKOlZfnir6_5Tv4hHyNF8sv94f7lxA9iK3ApUuT3wmGuQ', 'wsAlgiZ_Bvncop-BGlua2FqsrKj7Ex8mgDN2F-UsfJ2yQpnwHODg9Q', 'wIjqpBXazXUZmqJ8vTKF0yUXjNihX9JSEfk3-3aFQbM-DBtu2ccnVQ']

api_key_header = APIKeyHeader(name="x-api-key", auto_error=False)

def get_api_key(api_key_header: str = Depends(api_key_header)):
    if api_key_header in API_KEYS:
        return api_key_header
    raise HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail="Invalid or missing API Key",
    )