Skip to content

Conversation

@bokelley
Copy link
Contributor

Summary

Fixes 400 errors when calling GAM API with service account authentication by wrapping credentials in the required GoogleCredentialsClient wrapper.

Problem

AdManagerClient requires a googleads.oauth2.GoogleOAuth2Client subclass, but the code was passing raw google.oauth2.service_account.Credentials objects directly, causing 400 errors with incorrect argument signatures.

Solution

  • Wrap google.oauth2.service_account.Credentials in oauth2.GoogleCredentialsClient before returning from _get_service_account_credentials()
  • Apply fix to both JSON string and file-based service account credential paths
  • Update tests to verify returned object is GoogleCredentialsClient
  • Add test to confirm OAuth2 client compatibility with AdManagerClient

Changes

File: src/adapters/gam/auth.py

  • Line 100: Wrap credentials in oauth2.GoogleCredentialsClient() for JSON string path
  • Line 111: Wrap credentials in oauth2.GoogleCredentialsClient() for file path

File: tests/unit/test_gam_service_account_auth.py

  • Update test_service_account_credentials_creation to verify GoogleCredentialsClient wrapper
  • Add test_service_account_returns_compatible_oauth2_client to verify GoogleOAuth2Client inheritance

Test Results

✅ All 8 service account auth tests pass
✅ All 35 GAM unit tests pass
✅ All 846 unit tests pass
✅ All 174 integration tests pass

References

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Wrap service account credentials in GoogleCredentialsClient to ensure
compatibility with AdManagerClient. The AdManagerClient requires a
googleads OAuth2 client wrapper (GoogleOAuth2Client subclass), not raw
google.auth credentials.

Changes:
- Wrap Credentials objects in oauth2.GoogleCredentialsClient before
  returning from _get_service_account_credentials()
- Update tests to verify returned object is GoogleCredentialsClient
- Add test to confirm OAuth2 client compatibility with AdManagerClient

This fixes 400 errors when calling GAM API with service account auth.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bokelley bokelley merged commit 6d7a378 into main Oct 24, 2025
8 checks passed
EmmaLouise2018 pushed a commit that referenced this pull request Oct 24, 2025
Wrap service account credentials in GoogleCredentialsClient to ensure
compatibility with AdManagerClient. The AdManagerClient requires a
googleads OAuth2 client wrapper (GoogleOAuth2Client subclass), not raw
google.auth credentials.

Changes:
- Wrap Credentials objects in oauth2.GoogleCredentialsClient before
  returning from _get_service_account_credentials()
- Update tests to verify returned object is GoogleCredentialsClient
- Add test to confirm OAuth2 client compatibility with AdManagerClient

This fixes 400 errors when calling GAM API with service account auth.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
danf-newton pushed a commit to Newton-Research-Inc/salesagent that referenced this pull request Nov 24, 2025
Wrap service account credentials in GoogleCredentialsClient to ensure
compatibility with AdManagerClient. The AdManagerClient requires a
googleads OAuth2 client wrapper (GoogleOAuth2Client subclass), not raw
google.auth credentials.

Changes:
- Wrap Credentials objects in oauth2.GoogleCredentialsClient before
  returning from _get_service_account_credentials()
- Update tests to verify returned object is GoogleCredentialsClient
- Add test to confirm OAuth2 client compatibility with AdManagerClient

This fixes 400 errors when calling GAM API with service account auth.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
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