Skip to content

Added Exception Handeling On Cognito Validation Request #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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