cognite-sdk-python icon indicating copy to clipboard operation
cognite-sdk-python copied to clipboard

Add support for credential providers with the ability to refresh tokens in Pyodide

Open evertoncolling opened this issue 2 years ago • 2 comments

The latest release of the Cognite Python SDK adds support for Pyodide and it works great if the client is instantiated with a Token generated somewhere else. Any of the current credential providers that rely on msal are not working in Pyodide and some work might need to be done to patch msal to work without regular requests.

evertoncolling avatar Feb 20 '23 11:02 evertoncolling

Adding to the issue: For client credentials (OAuthClientCredentials), which doesn't use the msal package, the error is different:

JsException:
  NetworkError:
    Failed to execute 'send' on 'XMLHttpRequest':
      Failed to load 'https://login.microsoftonline.com/0d75f6b8-c6b9-4e84-baca-503e08aa7e4a/oauth2/v2.0/token'.

haakonvt avatar Feb 21 '23 11:02 haakonvt

Adding another similar-in-nature issue: Calling e.g. client.iam.service_accounts.list() which for many projects have been deactivated and returning 404, will raise a pyodide.JsException instead of subclass of CogniteException like CogniteAPIError. Needs to add or patch a check for it.

Found by @ks93

https://pyodide.org/en/0.19.1/usage/api/python-api.html#pyodide.JsException

haakonvt avatar Mar 29 '23 10:03 haakonvt