Skip to content

Commit

Permalink
perf(auth): remove urljoin to prevent non-http URI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brucetony committed Mar 21, 2024
1 parent 18eb0ca commit 37fa44e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions gateway/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Handle the authorization and authentication of services."""
from urllib.parse import urljoin

import requests
from fastapi import Security, HTTPException
Expand All @@ -12,7 +11,7 @@
from gateway.conf import gateway_settings
from gateway.models.conf import AuthConfiguration, Token

IDP_ISSUER_URL = urljoin(gateway_settings.IDP_URL, "/".join(["realms", gateway_settings.IDP_REALM]))
IDP_ISSUER_URL = gateway_settings.IDP_URL.rstrip("/") + "/" + "/".join(["realms", gateway_settings.IDP_REALM])

# IDP i.e. Keycloak
realm_idp_settings = AuthConfiguration(
Expand Down Expand Up @@ -45,7 +44,7 @@ async def get_idp_public_key() -> str:

async def get_hub_public_key() -> dict:
"""Get the central hub service public key."""
hub_jwks_ep = urljoin(gateway_settings.HUB_AUTH_SERVICE_URL, "/jwks")
hub_jwks_ep = gateway_settings.HUB_AUTH_SERVICE_URL.rstrip("/") + "/jwks"
return requests.get(hub_jwks_ep).json()


Expand Down Expand Up @@ -85,7 +84,7 @@ async def get_hub_token() -> dict:
"""Automated method for getting a token from the central Hub service."""
hub_user, hub_pwd = gateway_settings.HUB_USERNAME, gateway_settings.HUB_PASSWORD
payload = {"username": hub_user, "password": hub_pwd}
token_route = urljoin(gateway_settings.HUB_AUTH_SERVICE_URL, "/token")
token_route = gateway_settings.HUB_AUTH_SERVICE_URL.rstrip("/") + "/token"
resp = requests.post(token_route, data=payload)

if not resp.ok:
Expand Down

0 comments on commit 37fa44e

Please sign in to comment.