Spaces:
Sleeping
Sleeping
Download backend/app/auth/jwt_handler.py from ApyHTML19/PaperBrainAI: direct link, hf CLI and curl.
- Browser
- Download file 558 Bytes
-
https://huggingface.co/spaces/ApyHTML19/PaperBrainAI/resolve/main/backend/app/auth/jwt_handler.py
- Command line
-
hf download hf://spaces/ApyHTML19/PaperBrainAI/backend/app/auth/jwt_handler.py
-
curl -L -o jwt_handler.py https://huggingface.co/spaces/ApyHTML19/PaperBrainAI/resolve/main/backend/app/auth/jwt_handler.py
558 Bytes
| from datetime import datetime, timedelta | |
| from jose import JWTError, jwt | |
| SECRET_KEY = "smartstudy_secret_key_2024_change_in_production" | |
| ALGORITHM = "HS256" | |
| ACCESS_TOKEN_EXPIRE_HOURS = 24 | |
| def create_token(data: dict) -> str: | |
| payload = data.copy() | |
| payload["exp"] = datetime.utcnow() + timedelta(hours=ACCESS_TOKEN_EXPIRE_HOURS) | |
| return jwt.encode(payload, SECRET_KEY, algorithm=ALGORITHM) | |
| def decode_token(token: str) -> dict: | |
| try: | |
| return jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) | |
| except JWTError: | |
| return None |