Skip to main content
Committed ⭐️⭐️⭐️
December 1, 2022
Solved

Client id for the Python-SDK

  • December 1, 2022
  • 13 replies
  • 775 views

Hello,
I have a Python project that uses publicdata project of Open Industrial Data. I am trying to refactor the authentication step to use Python-SDK with OAuth since the API keys are (being) deprecated.
To do so, I need the parameters token_url, client_id, client_secret, scopes.
I am setting the parameters as such:

cognite_tenant_id = "48d5043c-cf70-4c49-881c-c638f5796997"
token_url=f"https://login.microsoftonline.com/{cognite_tenant_id}/oauth2/v2.0/authorize"

client_id=???

client_secret=<client secret generated from Open Industrial Data https://hub.cognite.com/open-industrial-data-211>

scopes=["https://api.cognitedata.com/user_impersonation"]

I would like to know if we can use the already defined Cognite tenant in AAD with Tenant Id “48d5043c-cf70-4c49-881c-c638f5796997” ? Are you providing the client id for that then? Similar to the ones publicly provided for Postman and JS-SDK? Please also note that I cannot use interactive login since it is not a one-off script.
Moreover, I cannot register an app in AAD as the documentation says, since I don’t have an active Azure subscription, or a Microsoft product/service that entitles me to use free/paid AAD.
Regards,
Arian

Best answer by Maria Fonseca

Hello, I have proceed to clarify on this article which details you should use for Python SDK 

 

Details to create the Cognite client when using Postman and Python SDK

  • Tenant ID - 48d5043c-cf70-4c49-881c-c638f5796997,

  • Client ID - 1b90ede3-271e-401b-81a0-a4d52bea3273,

  • project=publicdata,

  • CDF_CLUSTER - api

  • App name: OID-Api

 

You can get the client secret by using the Widget in Open Industrial Data and selecting “Others”. This is explained with more detail in 

Please let me know if this resolve your concerns.

13 replies

Anders Brakestad
Seasoned ⭐️⭐️⭐️
Seasoned ⭐️⭐️⭐️
December 13, 2022

When I use this an interactive log in window pops up - is this what you refer to? Then it caches after. 

arianAuthor
Committed ⭐️⭐️⭐️
December 13, 2022

When I use this an interactive log in window pops up - is this what you refer to? Then it caches after. 

Yes exactly 🙂.  My script is deployed remotely so I can’t do an interactive login at all. Unless I mimic a browser on a headless server 🤓

Murad Sæter
Practitioner ⭐️⭐️⭐️
Practitioner ⭐️⭐️⭐️
January 10, 2023

Looking at your scopes parameter it’s a bit wrong, it should only contain .default and not user_impersonation:

scopes=[f"{cognite_base_url}/.default"]