Commit 2078b53e authored by Manuel's avatar Manuel

moved token_service into modules/

parent 1b00f4c9
# global import
from security import security_util
from typing import List
import logging
def _verify(token:str, roles:List[str]=[]):
try:
token_info = security_util.decodeToken(token, roles=roles)
return token_info
except Exception as e:
LOGGER = logging.getLogger(__name__)
LOGGER.error("ERROR DURING TOKEN VALIDATION: "+str(e))
return None
def verifyTokenRegular(token, required_scopes):
return _verify(token)
def verifyTokenAdmin(token, required_scopes):
return _verify(token, roles=["a"])
......@@ -3,9 +3,9 @@ securityDefinitions:
type: apiKey
name: Authorization
in: header
x-apikeyInfoFunc: "services.token_service.verifyTokenRegular"
x-apikeyInfoFunc: "security_util.verifyTokenRegular"
JwtAdmin:
type: apiKey
name: Authorization
in: header
x-apikeyInfoFunc: "services.token_service.verifyTokenAdmin"
x-apikeyInfoFunc: "security_util.verifyTokenAdmin"
......@@ -76,3 +76,18 @@ def decodeToken(token: str, roles:List[str]=[]) -> Dict:
TokenStash.add(token, data["username"], data["role"])
return {"sub": data["username"], "role": data["role"]}
def _verify(token:str, roles:List[str]=[]):
try:
token_info = decodeToken(token, roles=roles)
return token_info
except Exception as e:
print("ERROR DURING TOKEN VALIDATION: "+str(e))
return None
def verifyTokenRegular(token, required_scopes):
return _verify(token)
def verifyTokenAdmin(token, required_scopes):
return _verify(token, roles=["a"])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment