ratingprocess/Utils/Authentication/TokenUtil.py

18 lines
475 B
Python
Raw Normal View History

2022-11-14 17:05:13 +08:00
import jwt
2022-11-18 15:11:47 +08:00
from jwt import PyJWTError
2022-11-14 17:05:13 +08:00
from fastapi import HTTPException
from Utils.Authentication import Config
def decode_token(token: str):
2022-11-18 15:11:47 +08:00
2022-11-14 17:05:13 +08:00
try:
payload = jwt.decode(token, Config.SECRET_KEY, algorithms=[Config.ALGORITHM])
except jwt.exceptions.ExpiredSignatureError:
2022-11-18 15:11:47 +08:00
raise HTTPException(status_code=401, detail="Token Has Expired")
except PyJWTError:
2022-11-14 17:05:13 +08:00
raise HTTPException(status_code=401, detail="Invalid Token")
return payload