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.2.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.2-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydc_auth-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 0e065611f648f82234c23aec4f6649f2c9ed5beffab080cedd7d4b28f8341e45
MD5 4970f1b04466973dd9487fa78462da86
BLAKE2b-256 2791d5378948308938d2e1fb36f1269e179507d8cbc89982ecb16d670da64818

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydc_auth-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 99ef1e248c24c5989bfaa23a220163ab00af27fb17805b7bfc230c869397cc9d
MD5 06c41fc39c31d23c50bbb36ba02d58f5
BLAKE2b-256 b291f559dc8152a684a529dee3958b3257ce66d733780dc360049d1cf5c5e63e

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