Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/django_cognito_jwt/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from django.core.cache import cache
from django.utils.functional import cached_property
from jwt.algorithms import RSAAlgorithm
from logging import getLogger

logger = getLogger("django.request")


class TokenError(Exception):
Expand All @@ -27,10 +30,14 @@ def pool_url(self):

@cached_property
def _json_web_keys(self):
response = requests.get(self.pool_url + "/.well-known/jwks.json")
response.raise_for_status()
json_data = response.json()
return {item["kid"]: json.dumps(item) for item in json_data["keys"]}
try:
response = requests.get(self.pool_url + "/.well-known/jwks.json")
response.raise_for_status()
json_data = response.json()
return {item["kid"]: json.dumps(item) for item in json_data["keys"]}
except (ConnectionError, Exception) as e:
logger.exception(e)
return {}

def _get_public_key(self, token):
try:
Expand Down