diff options
Diffstat (limited to 'api/util/check_api_key.py')
-rw-r--r-- | api/util/check_api_key.py | 21 |
1 files changed, 0 insertions, 21 deletions
diff --git a/api/util/check_api_key.py b/api/util/check_api_key.py deleted file mode 100644 index 9c4c22e..0000000 --- a/api/util/check_api_key.py +++ /dev/null @@ -1,21 +0,0 @@ -from fastapi import Security, HTTPException, Depends, status -from fastapi.security import APIKeyHeader - -from models import User -from api.util.db_dependency import get_db - -""" -Make sure the provided API key is valid, then return the user's ID -""" -api_key_header = APIKeyHeader(name="X-API-Key") - - -def check_api_key( - api_key_header: str = Security(api_key_header), db=Depends(get_db) -) -> str: - response = db.query(User).filter(User.api_key == api_key_header).first() - if not response: - raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid API key" - ) - return {"value": api_key_header, "owner": response.id} |