Skip to content

Add optional subject delegation support for service account authentication#4

Open
varelaerick wants to merge 2 commits intogoogleads:mainfrom
varelaerick:main
Open

Add optional subject delegation support for service account authentication#4
varelaerick wants to merge 2 commits intogoogleads:mainfrom
varelaerick:main

Conversation

@varelaerick
Copy link
Copy Markdown

Add support for user impersonation via GOOGLE_ADS_SUBJECT environment variable when using service account credentials.

Changes:

  • Add _get_subject() function to read subject from environment
  • Enhance _create_credentials() to apply subject delegation for service accounts
  • Maintain full backward compatibility - no changes to existing behavior
  • Add logging for authentication method used

Usage:
Set GOOGLE_ADS_SUBJECT=user@example.com when using service account credentials with domain-wide delegation enabled.

Requirements:

  • Service account credentials (not OAuth)
  • Domain-wide delegation configured in Google Workspace Admin

Copy link
Copy Markdown
Contributor

@ZLeventer ZLeventer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subject delegation for service accounts is the right pattern for enterprise setups where the Google Ads account is managed through a Workspace domain with domain-wide delegation enabled.

The implementation correctly:

  • Only activates when both GOOGLE_ADS_SUBJECT and a service account credential file are present
  • Falls through to standard ADC when either is missing
  • Uses credentials.with_subject() which is the documented approach for Google service account impersonation

Good defensive check on creds_info.get('type') == 'service_account' — prevents the subject param from silently being ignored when someone accidentally sets it with OAuth user credentials.

The README addition with the full JSON config example is helpful — MCP server setup docs that include working copy-paste configs get adopted much faster.

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.

2 participants