Commit 3e752fb6 authored by Manuel's avatar Manuel

restGateway added user response to verify endpoint

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