moved to single project
This commit is contained in:
27
api/auth.py
Executable file
27
api/auth.py
Executable file
@ -0,0 +1,27 @@
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user