mirror of
https://github.com/fusion44/blitz_api.git
synced 2026-08-14 12:02:46 +02:00
27 lines
667 B
Python
27 lines
667 B
Python
import time
|
|
from typing import Dict
|
|
|
|
import jwt
|
|
from decouple import config
|
|
|
|
JWT_SECRET = config("secret")
|
|
JWT_ALGORITHM = config("algorithm")
|
|
|
|
|
|
def signJWT() -> Dict[str, str]:
|
|
payload = {"user_id": "admin", "expires": time.time() + 300}
|
|
token = jwt.encode(payload, JWT_SECRET, algorithm=JWT_ALGORITHM)
|
|
return token_response(token)
|
|
|
|
|
|
def token_response(token: str):
|
|
return {"access_token": token}
|
|
|
|
|
|
def decodeJWT(token: str) -> dict:
|
|
try:
|
|
decoded_token = jwt.decode(
|
|
token, JWT_SECRET, algorithms=[JWT_ALGORITHM])
|
|
return decoded_token if decoded_token["expires"] >= time.time() else None
|
|
except:
|
|
return {}
|