Spaces:
Runtime error
Runtime error
File size: 940 Bytes
4986f6d 206aa5a 4986f6d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
from fastapi import Depends, HTTPException, status
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from jwt import InvalidTokenError
from app import logger
from firebase_admin import auth
security = HTTPBearer()
async def get_current_user(
credentials: HTTPAuthorizationCredentials = Depends(security),
):
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
headers={"WWW-Authenticate": "Bearer "},
)
try:
payload = auth.verify_id_token(credentials.credentials)
except InvalidTokenError as e:
logger.info(e)
raise credentials_exception
except ValueError as e:
logger.info(e)
raise credentials_exception
except Exception as e:
logger.info(e)
print(e)
raise credentials_exception
return payload
|