Skip to main content

JWT Bearer Auth client for generating Salesforce Data Cloud Bearer Access Token

Project description

pydc-auth

Auth helpers for Salesforce and Salesforce Data Cloud (A360):

  • Build a signed JWT for the OAuth 2.0 JWT Bearer flow
  • Exchange that JWT for a Salesforce access token
  • Exchange the Salesforce token for a Data Cloud access token (/services/a360/token)

Python 3.12+ • Uses httpx, PyJWT, pydantic, tenacity, python-dotenv
Import name: pydc_auth (underscore) • Distribution name: pydc-auth (hyphen)


Installation

From PyPI:

pip install pydc-auth

Quick Start

from pydc_auth import DataCloudTokenGenerator

dc = DataCloudTokenGenerator()
dc_token = dc.get_dc_token()  # pydantic model with .access_token and .instance_url

print("DC instance:", dc_token.instance_url)
print("Bearer:", dc_token.access_token[:24], "…")

Configuration (Environment Variables)

The following environment are required by the library. Set as environment variables or in a .env file (loaded by python-dotenv).

Required Variables for base JWT Creation:

Variable Purpose
SALESFORCE_APP_SUBJECT Username of the integration user (JWT sub)
SALESFORCE_APP_PRIVATE_KEY Filesystem path to your private key (PEM)
SALESFORCE_APP_CONSUMER_KEY Connected App Consumer Key (JWT iss)
SALESFORCE_ORGANIZATION_ID Org ID (read by code; not included in JWT claims)

Required Variables for Salesforce Token Exchange:

Variable Purpose
SALESFORCE_INSTANCE_URL e.g., https://login.salesforce.com (or https://test.salesforce.com)
SALESFORCE_TOKEN_GRANT_TYPE OAuth grant type (defaults to JWT Bearer: urn:ietf:params:oauth:grant-type:jwt-bearer)

Required Variables for Data Cloud Token Exchange:

Variable Purpose
SALESFORCE_INSTANCE_URL Used to construct the Data Cloud token URL (falls back to the SF token’s instance URL)
DATA_CLOUD_TOKEN_GRANT_TYPE Token exchange grant type (set per your org/API configuration)
DATA_CLOUD_SUBJECT_TOKEN_TYPE Subject token type for exchange (set per your org/API configuration)

Example .env:

# JWT
SALESFORCE_APP_SUBJECT="integration.user@example.com"
SALESFORCE_APP_PRIVATE_KEY="/secure/path/private.key"
SALESFORCE_APP_CONSUMER_KEY="3MVG9..."
SALESFORCE_ORGANIZATION_ID="00D..."

# SF token exchange
SALESFORCE_INSTANCE_URL="https://login.salesforce.com"
# SALESFORCE_TOKEN_GRANT_TYPE="urn:ietf:params:oauth:grant-type:jwt-bearer"  # default

# DC token exchange (values vary by org/config)
DATA_CLOUD_TOKEN_GRANT_TYPE="urn:ietf:params:oauth:grant-type:token-exchange"
DATA_CLOUD_SUBJECT_TOKEN_TYPE="urn:ietf:params:oauth:token-type:access_token"

API Surface (minimal)

All return types are pydantic models unless noted.

DataCloudTokenGenerator:

get_dc_token() -> DCTokenResponse Uses SalesforceTokenGenerator to get an org token, then exchanges at …/services/a360/token.

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

pydc_auth-0.1.3.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

pydc_auth-0.1.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file pydc_auth-0.1.3.tar.gz.

File metadata

  • Download URL: pydc_auth-0.1.3.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for pydc_auth-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3876479c7198e0099e9118a6a9f98573d7bdd8f62236ad915e2954062884d75f
MD5 bb96c2713758c8c5485a6c892e9a6d6c
BLAKE2b-256 fffd2ee0a7f454c8ee3be57dd1b0facab1186e75fbf2212b7847c458d7fffa5a

See more details on using hashes here.

File details

Details for the file pydc_auth-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pydc_auth-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for pydc_auth-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ba7fcc2d0ffa928543fb64f1566afb62984ae858bcdc6b066441d9c164302ae6
MD5 00a9ff199592d166970ccb041d169b56
BLAKE2b-256 88c3475b0565552598cf60fac562909995877c035c53b749d297f2cce7741c14

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