Skip to content

CRED-2146: Add PAT auth support to Python API client#3243

Draft
tausman wants to merge 2 commits intomasterfrom
tausman/cred-2146-python-pat-auth
Draft

CRED-2146: Add PAT auth support to Python API client#3243
tausman wants to merge 2 commits intomasterfrom
tausman/cred-2146-python-pat-auth

Conversation

@tausman
Copy link

@tausman tausman commented Mar 4, 2026

Why

Add Personal Access Token (PAT) authentication support to the Python API client. PATs authenticate via an Authorization: Bearer <PAT> header. This is in addition to (not replacing) the existing API key + app key auth — both can be sent simultaneously.

Behavior

  • Set DD_BEARER_TOKEN env var or pass access_token= to Configuration() to configure PAT auth
  • When configured, the Authorization: Bearer <token> header is sent alongside any configured DD-API-KEY and DD-APPLICATION-KEY headers
  • Auth methods are not mutually exclusive — all configured headers are sent, and the server uses whichever is valid
  • Aligns with the bearerAuth security scheme now defined in the OpenAPI spec (x-env-name: DD_BEARER_TOKEN)

Summary of changes

  • configuration.j2 / configuration.py: Uncommented the existing bearer auth handler in the template so the generator picks up bearerAuth from the OpenAPI spec automatically. Uses the standard access_token field. Added DD_BEARER_TOKEN env var loading.
  • api_client.j2 / api_client.py: No special branching for bearer auth — all configured auth headers flow through the regular auth loop.
  • tests/test_pat_auth.py: Unit tests covering configuration, auth settings, env var loading, and header behavior (all headers sent together, bearer-only, api-keys-only, endpoint without bearerAuth).

Test plan

  • 10 unit tests pass (python -m pytest tests/test_pat_auth.py -v)
  • Verified all three auth headers sent simultaneously when all credentials configured
  • Verified bearer-only and api-key-only paths work independently
  • Verified endpoints without bearerAuth in auth list don't send Authorization header
  • No secrets in committed files

PR Stack

API Client Libraries

OpenAPI Spec Changes

@tausman tausman force-pushed the tausman/cred-2146-python-pat-auth branch from 8374703 to fe5c4e4 Compare March 4, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant