diff --git a/config.ini b/config.ini index a3ad55f..499871a 100644 --- a/config.ini +++ b/config.ini @@ -6,4 +6,3 @@ CANDIG_KATSU_URL = [authz] CANDIG_OPA_URL = -CANDIG_VAULT_URL = diff --git a/entrypoint.sh b/entrypoint.sh index 0c701ad..49d79d5 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,6 +3,7 @@ if [[ -f "initial_setup" ]]; then sed -i s@\@$CANDIG_HTSGET_URL@ config.ini sed -i s@\@$CANDIG_KATSU_URL@ config.ini + sed -i s@\@$OPA_URL@ config.ini rm initial_setup fi diff --git a/query_server/config.py b/query_server/config.py index 7b92f8d..82c83c2 100644 --- a/query_server/config.py +++ b/query_server/config.py @@ -13,6 +13,7 @@ HTSGET_URL = config['DEFAULT']['CANDIG_HTSGET_URL'] KATSU_URL = config['DEFAULT']['CANDIG_KATSU_URL'] +OPA_URL = config['authz']['CANDIG_OPA_URL'] DEBUG_MODE = False if os.getenv("DEBUG_MODE", "1") == "1": diff --git a/query_server/openapi.yaml b/query_server/openapi.yaml index f1b8473..4ab001b 100644 --- a/query_server/openapi.yaml +++ b/query_server/openapi.yaml @@ -105,6 +105,20 @@ paths: $ref: '#/components/schemas/DiscoveryProgramBody' 5XX: $ref: "#/components/responses/5xxServerError" + /whoami: + get: + summary: Retrieve the user key (usually the email) for the currently logged-in user + description: Retrieve the user key (usually the email) for the currently logged-in user + operationId: query_operations.whoami + responses: + 200: + description: User info + content: + application/json: + schema: + $ref: '#/components/schemas/UserInfo' + 5XX: + $ref: "#/components/responses/5xxServerError" components: parameters: @@ -254,6 +268,13 @@ components: programs: type: array description: Per-program summary statistics + UserInfo: + type: object + description: Information about a user + properties: + key: + type: string + description: The user key associated with this user. Usually an email # ERROR SCHEMAS Error: type: object diff --git a/query_server/query_operations.py b/query_server/query_operations.py index 833a4b6..cab8fb3 100644 --- a/query_server/query_operations.py +++ b/query_server/query_operations.py @@ -4,6 +4,7 @@ import requests import secrets import urllib +from authx.auth import get_user_id, get_auth_token import config @@ -490,3 +491,24 @@ def discovery_query(treatment="", primary_site="", chemotherapy="", immunotherap summary_stats = censor_response(summary_stats) return fix_dicts(summary_stats), 200 + +@app.route('/whoami') +def whoami(): + # Grab information about the currently logged-in user + print(config.OPA_URL) + print(config.AUTHZ) + token = get_auth_token(request) + headers = { + "Authorization": f"Bearer {token}" + } + response = requests.post( + config.OPA_URL + f"/v1/data/idp/user_key", + headers=headers, + json={ + "input": { + "token": token + } + } + ) + print(response) + return { 'key': get_user_id(request, opa_url = config.OPA_URL) }