27 lines
682 B
Python
27 lines
682 B
Python
|
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('/opt/app/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)
|
||
|
}
|