Python OKTA and Salesforce

apologies is this is very basic, but I’m very new to Python (and programming in general) and need some help getting data out of Salesforce that requires SSO authentication through OKTA.

My organization just decided to enforce SSO with OKTA after a couple people fell for the most basic of phishing emails. Previously, we had the option to use our OKTA credentials to access salesforce but could also use salesforce credentials on login.salesforce.com I had been using simple salesforce to access salesforce (using userID, password, and token). I downloaded data using SOQL queries, did a lot of data cleanup and aggregation in Python, then published to Tableau server. With SSO enabled simple salesforce clearly no longer works.

Again, apologies if this is straight forward but I can’t find anything that is helpful for someone as… green in programming as I am.

If anyone has any resources they could point me to, or libraries that would help me move in the right direction it would be greatly greatly appreciated!

No need to apologize! I can certainly help you with that. Working with SSO authentication and accessing Salesforce through Okta can be a bit more involved than using simple Salesforce credentials. However, there are libraries available that can assist you in integrating Okta authentication with your Python code.

One popular library for working with Okta authentication in Python is the okta library. You can install it using pip:

pip install okta

The okta library provides an API client that you can use to authenticate with Okta and retrieve access tokens that can be used to access Salesforce. Here’s a basic example to help you get started:

from okta import Client

# Create an Okta client instance
okta_client = Client("https://your-okta-domain.okta.com", "your-api-key")

# Authenticate with Okta using your credentials
auth_response = okta_client.authenticate(username="your-username", password="your-password")

# Get the access token
access_token = auth_response["access_token"]

# Now you can use the access token to access Salesforce using the Salesforce API or libraries like simple-salesforce

In the example above, make sure to replace "https://your-okta-domain.okta.com" with the URL of your Okta domain and "your-api-key" with your Okta API key. Also, provide your Okta username and password in the authenticate method.

Once you have the access token, you can use it to authenticate and interact with Salesforce using libraries like simple-salesforce or the Salesforce REST API.

Keep in mind that this is just a basic example to help you get started. Depending on your specific setup and requirements, you may need to customize the authentication flow or handle additional steps. I also recommend to review the documentation of the okta library for more details and advanced usage.

I hope this helps you get started with integrating Okta authentication with Salesforce in Python! Let me know if you have any further questions.