27 lines
675 B
Python
Executable File

from jose import JWTError, jwt
import werkzeug
import os
from loguru import logger
import json
JWT_PUB_KEY = ""
try:
JWT_PUB_KEY = os.environ["JWT_PUB_KEY"]
except KeyError:
with open('./config/authservice.pub', 'r') as f:
JWT_PUB_KEY = f.read()
def decodeToken(token):
try:
return jwt.decode(token, JWT_PUB_KEY, audience="hv2")
except JWTError as e:
logger.error("{}".format(e))
raise werkzeug.exceptions.Unauthorized()
def testToken(user, token_info):
return {
"message": f"You are user_id {user} and the provided token has been signed by this issuers. Fine.",
"details": json.dumps(token_info)
}