Spaces:
Runtime error
Runtime error
Download app/utils/jwt_handler.py from ismaileghazi/test: direct link, hf CLI and curl.
- Browser
- Download file 639 Bytes
-
https://huggingface.co/spaces/ismaileghazi/test/resolve/main/app/utils/jwt_handler.py
- Command line
-
hf download hf://spaces/ismaileghazi/test/app/utils/jwt_handler.py
-
curl -L -o jwt_handler.py https://huggingface.co/spaces/ismaileghazi/test/resolve/main/app/utils/jwt_handler.py
639 Bytes
| from datetime import datetime, timedelta | |
| from jose import jwt, JWTError | |
| import os | |
| SECRET_KEY = os.getenv("JWT_SECRET", "secret") | |
| ALGORITHM = "HS256" | |
| ACCESS_TOKEN_EXPIRE_MINUTES = 30 | |
| def create_access_token(data: dict): | |
| to_encode = data.copy() | |
| expire = datetime.utcnow() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) | |
| to_encode.update({"exp": expire}) | |
| encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) | |
| return encoded_jwt | |
| def verify_token(token: str): | |
| try: | |
| payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) | |
| return payload | |
| except JWTError: | |
| return None | |