Skip to content

Commit be72803

Browse files
committed
fix: handle lookup for JWKS from within docker
1 parent c02994b commit be72803

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/stac_auth_proxy/middleware/EnforceAuthMiddleware.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
from dataclasses import dataclass
55
from typing import Annotated, Any, Optional, Sequence
6+
from urllib.parse import urlparse, urlunparse
67

78
import httpx
89
import jwt
@@ -45,7 +46,16 @@ def jwks_client(self) -> jwt.PyJWKClient:
4546
response = httpx.get(origin_url)
4647
response.raise_for_status()
4748
oidc_config = response.json()
48-
self._jwks_client = jwt.PyJWKClient(oidc_config["jwks_uri"])
49+
50+
# NOTE: We manually replace the origin of the jwks_uri in the event that
51+
# the jwks_uri is not available from within the proxy.
52+
oidc_url = urlparse(origin_url)
53+
jwks_uri = urlunparse(
54+
urlparse(oidc_config["jwks_uri"])._replace(
55+
netloc=oidc_url.netloc, scheme=oidc_url.scheme
56+
)
57+
)
58+
self._jwks_client = jwt.PyJWKClient(jwks_uri)
4959
except httpx.HTTPStatusError as e:
5060
logger.error(
5161
"Received a non-200 response when fetching OIDC config: %s",
@@ -121,6 +131,8 @@ def validate_token(
121131

122132
# Parse & validate token
123133
try:
134+
print(f"{token=}")
135+
print(f"{ self.jwks_client.get_signing_key_from_jwt(token)=}")
124136
key = self.jwks_client.get_signing_key_from_jwt(token).key
125137
payload = jwt.decode(
126138
token,

0 commit comments

Comments
 (0)