Skip to main content

A simple OAuth client Salesforce. Connect notebooks or CLIs with a browser-based flow.

Project description

SF-OAUTH

A simple OAuth client for Salesforce

This package lets you connect to Salesforce using a browser-based flow, much like you would with the sf cli or similar tools. It frees you from having to manage security tokens for all of your sandbox environments. It is intended to be used in Python Notebooks or CLI tools.

Usage

Use an OAuthFlow object to generate an instance_url and session_id to pass to a simple_salesforce Salesforce client.

from sf_oauth import OAuthFlow
from simple_salesforce import Salesforce

flow = OAuthFlow(domain='test')
flow.connect() # This will open a browser window to 'https://test.salesforce.com' for you to sign in

sf = Salesforce(instance_url=flow.instance_url, session_id=flow.session_id)

Instantiate multiple clients to connect to different orgs at the same time

from sf_oauth import OAuthFlow
from simple_salesforce import Salesforce

prod_flow = OAuthFlow(alias='prod')
sandbox_flow = OAuthFlow(alias='sandbox', domain='test')

prod = Salesforce(instance_url=prod_flow.instance_url, session_id=prod_flow.session_id)
sandbox = Salesforce(instance_url=sandbox_flow.instance_url, session_id=sandbox_flow.session_id)

Access tokens are cached by default. You can disconnect to log out and delete your access tokens.

from sf_oauth import OAuthFlow
flow = OAuthFlow(domain='test')
flow.connect() # We already connected once, so it loads access from the cache rather than opening a browser
flow.disconnect() # Log out and forget cached token

Setting up your External Client App

The OAuthFlow needs an External Client App configured in your org to work. You can easily set this up yourself.

  1. Go to Setup and use the Quick Find box to find the "External Client App Manager"
  2. Click "New External Client App"
  3. Fill out the "New External Client App" form
  4. Enter a Name and Email as appropriate
  5. Set the "Distribution State" to "Local"
  6. Check the "Enable OAuth"
  7. Set the "Callback URL" to "http://localhost:5000" (remote notebook environments may need to be configured differently)
  8. Select the OAuth Scopes you need. For trusted, internal usage, you can use full.
  9. Select "Enable Authorization Code and Credentials Flow"
  10. Select "Require Proof Key for Code Exchange (PKCE) extension for Supported Authorization Flows"
  11. Click "Create"
  12. Open the newly created Client App, go to the "Settings" tab, and click "Consumer Key and Secret." You will save the "Consumer Key" to the SF_OAUTH_CLIENT_ID environment variable or pass it into the OAuthFlow constructor.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sf_oauth-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sf_oauth-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file sf_oauth-0.1.1.tar.gz.

File metadata

  • Download URL: sf_oauth-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for sf_oauth-0.1.1.tar.gz
Algorithm Hash digest
SHA256 09eeef647a0a5e4c81bfddbabda98b6b1448e2b1545e41db7c97a2e9ee0e8fd6
MD5 1d6f0ffcd05c2bdf4f377a9c15654869
BLAKE2b-256 1773a1c4faa9f1716b8da89c7cede0f5fef633997eca4f9adf31bcc5238f8a23

See more details on using hashes here.

File details

Details for the file sf_oauth-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sf_oauth-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for sf_oauth-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1cbe41d63bd3a822c70d6d4268c77eef1c569f876da25f6b60eca831815295fc
MD5 df0994bd17e69896996d25e71a469442
BLAKE2b-256 91fa0f4de58ff755e3b7360734d5e71de56c0ca659345ccda211f12965ed791b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page