Files
whisperbox-transcribe/app/security.py
Felix Spöttel b3a38846ba feat: add job & artifact tables
* remove `accounts` table in favor of a simple API key auth
2023-01-05 12:03:41 +01:00

17 lines
503 B
Python

from hmac import compare_digest
from fastapi import Depends, HTTPException
from fastapi.security import OAuth2PasswordBearer
from app.config import settings
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
def authenticate_api_key(token: str = Depends(oauth2_scheme)) -> None:
if not token:
raise HTTPException(status_code=422)
# use compare_digest to counter timing attacks.
if not compare_digest(settings.API_SECRET, token):
raise HTTPException(status_code=401)