Download app/dependencies.py from Hammad712/Video-Rag: direct link, hf CLI and curl.
- Browser
- Download file 935 Bytes
-
https://huggingface.co/spaces/Hammad712/Video-Rag/resolve/main/app/dependencies.py
- Command line
-
hf download hf://spaces/Hammad712/Video-Rag/app/dependencies.py
-
curl -L -o dependencies.py https://huggingface.co/spaces/Hammad712/Video-Rag/resolve/main/app/dependencies.py
935 Bytes
| from fastapi import Depends, HTTPException | |
| from fastapi.security import OAuth2PasswordBearer | |
| import jwt | |
| from .config import settings | |
| from .services.auth import get_user | |
| from .models.user import TokenData | |
| oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/token") | |
| async def get_current_user(token: str = Depends(oauth2_scheme)): | |
| credentials_exception = HTTPException( | |
| status_code=401, | |
| detail="Could not validate credentials", | |
| headers={"WWW-Authenticate": "Bearer"}, | |
| ) | |
| try: | |
| payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM]) | |
| username: str = payload.get("sub") | |
| if username is None: | |
| raise credentials_exception | |
| token_data = TokenData(username=username) | |
| except jwt.PyJWTError: | |
| raise credentials_exception | |
| user = get_user(token_data.username) | |
| if user is None: | |
| raise credentials_exception | |
| return user |