supertokens / supertokens-python

Python SDK for SuperTokens

Home Page:https://supertokens.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Switch away use of urllib.request

rishabhpoddar opened this issue · comments

This is an old lib and adds a user-agent that is banned by services like cloudflare. As a result, fetching JWKS from the core fails. We should switch to using requests lib like so:

def reload(self):
        try:
            with requests.get(self.uri, timeout=self.timeout_sec) as response:
                self.jwk_set = PyJWKSet.from_dict(response.json())  # type: ignore
                self.last_fetch_time = get_timestamp_ms()

(The above snippet is replacing the use of urllib.request in jwks.py file)

commented

Here is an updated code snippet which will fit into the existing code, the previous code would not raise an Exception

        try:
            with requests.get(self.uri, timeout=self.timeout_sec) as response:
                response.raise_for_status() # raise exception
                self.jwk_set = PyJWKSet.from_dict(response.json())  # type: ignore
                self.last_fetch_time = get_timestamp_ms()
        except requests.HTTPError:
            raise JWKSRequestError("Failed to fetch jwk set from the configured uri")

This has been fixed in version >= 0.14.4