Skip to content

Commit 0ff1e7d

Browse files
committed
fix: Use requests lib for fetching jwks
1 parent 506f154 commit 0ff1e7d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
### Changes
1212

1313
- Use `useStaticSigningKey` instead of `use_static_signing_key` in `create_jwt` function. This was a bug in the code.
14+
- Use request library instead of urllib to fetch JWKS keys ([#344](https://github.com/supertokens/supertokens-python/issues/344))
1415

1516

1617
## [0.14.3] - 2023-06-7

supertokens_python/recipe/session/jwks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
2-
import urllib.request
2+
import requests
33
from typing import List, Optional
4-
from urllib.error import URLError
54

65
from jwt import PyJWK, PyJWKSet
76
from jwt.api_jwt import decode_complete as decode_token # type: ignore
@@ -46,10 +45,11 @@ def __init__(
4645
def fetch(self):
4746
try:
4847
log_debug_message("Fetching jwk set from the configured uri")
49-
with urllib.request.urlopen(self.uri, timeout=self.timeout_sec) as response:
48+
with requests.get(self.uri, timeout=self.timeout_sec) as response:
49+
response.raise_for_status()
5050
self.cached_jwks = PyJWKSet.from_dict(json.load(response)) # type: ignore
5151
self.last_fetch_time = get_timestamp_ms()
52-
except URLError:
52+
except requests.HTTPError:
5353
raise JWKSRequestError("Failed to fetch jwk set from the configured uri")
5454

5555
def is_cooling_down(self) -> bool:

0 commit comments

Comments
 (0)