Commit 3e752fb6 authored by Manuel's avatar Manuel

restGateway added user response to verify endpoint

parent 72f8b967
# global import
from security import security_util
import logging
def verifyTokenRegular(token, required_scopes):
print("gonna verify token: "+token)
LOGGER = logging.getLogger(__name__)
try:
token_info = security_util.decodeToken(token)
print("TOKEN INFO: "+str(token_info))
LOGGER.info("TOKEN INFO: "+str(token_info))
return token_info
except Exception as e:
print("ERROR DURING TOKEN VALIDATION: "+str(e))
LOGGER.error("ERROR DURING TOKEN VALIDATION: "+str(e))
return None
......
......@@ -51,20 +51,29 @@ def decodeToken(token: str) -> Dict:
raise ValueError('Invalid JWT token (must be a Bearer string)')
token = token[7:]
url = f'https://{network_constants.REST_GATEWAY_HOSTNAME}:{network_constants.REST_GATEWAY_REST_PORT}/api/tokens/{token}'
response = requests.post(
f'https://{network_constants.REST_GATEWAY_HOSTNAME}:{network_constants.REST_GATEWAY_REST_PORT}/api/tokens/{token}',
url,
verify=False,
headers={'User-Agent': 'Chrome', 'Accept': 'application/json', 'Content-Type': 'application/json'},
proxies = { "http":"http://proxy.uni-klu.ac.at:3128/", "https":"http://proxy.uni-klu.ac.at:3128/" }
# proxies = { "http":"http://proxy.uni-klu.ac.at:3128/", "https":"http://proxy.uni-klu.ac.at:3128/" }
)
if response.status_code != 200:
raise ValueError(
f"Validation of token failed ({response.status_code})!")
# TODO replace with token information
data = json.dumps(response.text)
if not "username" in data:
print("Verification Response (raw): "+response.text)
print("Verification Response: "+data)
print(type(data))
if not "username" in data or not "role" in data:
raise ValueError(
f"Validation of token failed (missing field in verification response)!")
......
......@@ -7,6 +7,7 @@ from services.token_service import TokenService
from flask import request, Response
import bcrypt
import jwt
import json
def secret():
return "Pineapple does not belong to pizza!"
......@@ -22,9 +23,9 @@ def verify(token):
'''
try:
TokenService.verify("Bearer "+token)
user = TokenService.verify("Bearer "+token)
return Response(status = 200)
return Response(status = 200, response=json.dumps(user.to_serializable_dict()))
except ValueError as e:
return Response(status=401, response=str(e))
......
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