HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/anaconda3/Lib/site-packages/anaconda_cloud_auth/jwt.py
import ssl
from typing import Any
from typing import Dict
from typing import Union

import requests
from jwt import PyJWKClient
from jwt import PyJWKClientError
from jwt import PyJWKSet


class JWKClient(PyJWKClient):
    def fetch_data(self) -> Dict[str, Any]:
        # This method fails in the original class due to using urlopen.
        # The jwks URI likely blocks the user-agent used by urlopen
        jwk_set: Union[Dict[str, Any], None] = None

        ssl_verify = True
        if (
            self.ssl_context is not None
            and self.ssl_context.verify_mode == ssl.CERT_NONE
        ):
            ssl_verify = False

        try:
            jwk_set = requests.get(self.uri, verify=ssl_verify).json()
        except requests.exceptions.RequestException as e:
            raise PyJWKClientError(f'Fail to fetch data from the url, err: "{e}"')
        else:
            assert jwk_set is not None
            return jwk_set
        finally:
            if self.jwk_set_cache is not None and jwk_set is not None:
                self.jwk_set_cache.put(PyJWKSet(jwk_set["keys"]))