Skip to content
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

Handle errors retrieving jwks #611

Open
wants to merge 4 commits into
base: main
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
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")
Loading