27 lines
675 B
Python
Raw Permalink Normal View History

2021-08-02 16:52:31 +02:00
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:
2021-08-29 13:17:57 +02:00
with open('./config/authservice.pub', 'r') as f:
2021-08-02 16:52:31 +02:00
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)
}