mirror of
https://github.com/bellingcat/whisperbox-transcribe.git
synced 2026-06-12 13:38:34 +03:00
feat: initial project setup
This commit is contained in:
26
app/security.py
Normal file
26
app/security.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import Depends, HTTPException
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from .db.base import get_db
|
||||
from .db.models import Account
|
||||
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||
|
||||
|
||||
def authenticate_api_key(
|
||||
db: Session = Depends(get_db),
|
||||
api_key: str = Depends(oauth2_scheme),
|
||||
) -> Account:
|
||||
try:
|
||||
account = db.query(Account).filter(Account.api_key == UUID(api_key)).one()
|
||||
except NoResultFound:
|
||||
raise HTTPException(status_code=401)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise HTTPException(status_code=422)
|
||||
|
||||
return account
|
||||
Reference in New Issue
Block a user