Spaces:
Runtime error
Runtime error
Refactor Dockerfile and clean up unused schemas; update Redis client initialization and environment configuration
a3aa6c1 Download src/utils/_jwt_util.py from sifars/keepme-backend: direct link, hf CLI and curl.
- Browser
- Download file 690 Bytes
-
https://huggingface.co/spaces/sifars/keepme-backend/resolve/main/src/utils/_jwt_util.py
- Command line
-
hf download hf://spaces/sifars/keepme-backend/src/utils/_jwt_util.py
-
curl -L -o _jwt_util.py https://huggingface.co/spaces/sifars/keepme-backend/resolve/main/src/utils/_jwt_util.py
690 Bytes
| import os | |
| import jwt | |
| from datetime import datetime, timedelta | |
| class JWTUtil: | |
| def __init__(self, algorithm="HS256"): | |
| self.secret_key = os.getenv("JWT_SECRET_KEY") | |
| self.algorithm = algorithm | |
| def generate_jwt(self, payload, expiration_minutes=60): | |
| payload["exp"] = datetime.now() + timedelta(minutes=expiration_minutes) | |
| return jwt.encode(payload, self.secret_key, algorithm=self.algorithm) | |
| def validate_jwt(self, token): | |
| try: | |
| return jwt.decode(token, self.secret_key, algorithms=[self.algorithm]) | |
| except jwt.ExpiredSignatureError: | |
| return None | |
| except jwt.InvalidTokenError: | |
| return None | |