CoolFace
Apppublic

FaizanMirZa77/FormatX

sourceHugging Faceupdated 13d agoView on Hugging Face
0likes
auth_middleware.py22 linesDownload Raw Back to root
1from fastapi import Depends, HTTPException, status2from fastapi.security import OAuth2PasswordBearer3from jwt_generator import verify_jwt_token, get_email_from_jwt4 5 6oauth2_scheme = OAuth2PasswordBearer(tokenUrl="login")7 8def get_authenticated_email(token: str = Depends(oauth2_scheme)):9    credentials_exception = HTTPException(10        status_code=status.HTTP_401_UNAUTHORIZED,11        detail="Could not validate credentials",12        headers={"WWW-Authenticate": "Bearer"},13    )14 15    if not verify_jwt_token(token):16        raise credentials_exception17 18    return get_email_from_jwt(token)19 20 21 22