Download app/api/deps.py from isold/meloon: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/isold/meloon/resolve/main/app/api/deps.py
- Command line
-
hf download hf://spaces/isold/meloon/app/api/deps.py
-
curl -L -o deps.py https://huggingface.co/spaces/isold/meloon/resolve/main/app/api/deps.py
1.27 kB
| from typing import Generator, Optional | |
| from fastapi import Depends, HTTPException, status | |
| from fastapi.security import OAuth2PasswordBearer | |
| from jose import jwt, JWTError | |
| from sqlalchemy.orm import Session | |
| import uvicorn | |
| import logging | |
| from app.core import security | |
| from app.core.config import settings | |
| from app.core.database import get_db | |
| from app.models.models import User | |
| from app.schemas import schemas | |
| oauth2_scheme = OAuth2PasswordBearer(tokenUrl="api/v1/auth/login") | |
| def get_current_user( | |
| db: Session = Depends(get_db), | |
| token: str = Depends(oauth2_scheme) | |
| ) -> User: | |
| print(f"[DEBUG] Auth Token: {token[:10]}..." if token else "[DEBUG] No Auth Token") | |
| credentials_exception = HTTPException( | |
| status_code=status.HTTP_401_UNAUTHORIZED, | |
| detail="Could not validate credentials", | |
| headers={"WWW-Authenticate": "Bearer"}, | |
| ) | |
| try: | |
| payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM]) | |
| email: str = payload.get("sub") | |
| if email is None: | |
| raise credentials_exception | |
| except JWTError: | |
| raise credentials_exception | |
| user = db.query(User).filter(User.email == email).first() | |
| if user is None: | |
| raise credentials_exception | |
| return user | |