Skip to content

Commit

Permalink
Handle JSONDecodeError exception
Browse files Browse the repository at this point in the history
  • Loading branch information
aristizabal95 committed Aug 20, 2024
1 parent fac2940 commit f57b563
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cli/medperf/comms/auth/token_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
wrapped the library's `JwksFetcher` to cache keys in the filesystem storage, and wrapped the
library's signature verifier to use this new `JwksFetcher`"""

import logging
from typing import Any
from medperf import config
import os
import json
from json import JSONDecodeError
from auth0.authentication.token_verifier import (
TokenVerifier,
JwksFetcher,
AsymmetricSignatureVerifier,
)

from medperf.exceptions import CommunicationAuthenticationError


class JwksFetcherWithDiskCache(JwksFetcher):
def _init_cache(self, cache_ttl: int) -> None:
Expand Down Expand Up @@ -53,4 +57,8 @@ def verify_token(token):
issuer=config.auth_idtoken_issuer,
audience=config.auth_client_id,
)
return token_verifier.verify(token)
try:
return token_verifier.verify(token)
except JSONDecodeError as e:
logging.error(e, exc_info=True)
raise CommunicationAuthenticationError("There was an issue verifying the token. Please try again")

0 comments on commit f57b563

Please sign in to comment.