Skip to content

Conversation

@kmoegling-scope3
Copy link
Contributor

Problem

The inventory sync endpoint was failing for tenants configured with service account authentication (like the weather tenant). The endpoint was hardcoded to only accept OAuth refresh tokens.

Error seen:

Sync failed: Please connect your GAM account before trying to sync inventory

Root cause:

  • sync_inventory() endpoint at src/admin/blueprints/inventory.py:405 checked for gam_refresh_token only
  • Weather tenant has valid service account credentials stored in adapter_config.gam_service_account_json
  • Service account auth was completely ignored

Solution

Modified the inventory sync endpoint to support both OAuth and service account authentication:

  1. Detect auth method: Check adapter_config.gam_auth_method field (or infer from available credentials)
  2. Service account path: Decrypt gam_service_account_json and create service account credentials
  3. OAuth path: Use existing refresh token flow (unchanged)
  4. Backward compatible: Falls back to inferring auth method for legacy configurations

Changes

  • Modified src/admin/blueprints/inventory.py:405-472
  • Added service account credential handling using decrypt_api_key()
  • Removed hard requirement for gam_refresh_token
  • Added proper error messages for missing credentials

Testing

  • ✅ Verified weather tenant has service account configured in production database
  • ✅ Confirmed gam_service_account_json field is populated and encrypted
  • ✅ Checked gam_auth_method field is set to service_account

Relates to

🤖 Generated with Claude Code

kmoegling-scope3 and others added 5 commits October 23, 2025 14:24
The inventory sync endpoint was hardcoded to only accept OAuth refresh
tokens, causing failures for tenants configured with service account
authentication.

**Problem:**
- `sync_inventory()` endpoint checked for `gam_refresh_token` only
- Weather tenant has valid service account credentials but sync failed
- Error: "GAM not configured for this tenant"

**Solution:**
- Detect auth method from `adapter_config.gam_auth_method` field
- Support both OAuth and service account authentication paths
- Decrypt and use `gam_service_account_json` for service accounts
- Fall back to inferring auth method for backward compatibility

**Changes:**
- Modified `src/admin/blueprints/inventory.py:405-472`
- Added service account credential handling
- Removed hard requirement for refresh token
- Uses `decrypt_api_key()` to decrypt service account JSON

**Tested:**
- Weather tenant has service account properly configured
- Fix enables inventory sync for service account tenants

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

Co-Authored-By: Claude <noreply@anthropic.com>
@bokelley bokelley merged commit 59bccc2 into adcontextprotocol:main Oct 23, 2025
8 checks passed
kmoegling-scope3 added a commit to kmoegling-scope3/salesagent that referenced this pull request Oct 23, 2025
PR adcontextprotocol#570 was merged but inventory sync still fails for service account
authentication with error: 'Credentials' object has no attribute 'CreateHttpHeader'

Root Cause:
- google.oauth2.service_account.Credentials lacks CreateHttpHeader method
- AdManagerClient requires 2-arg signature: (credentials, network_code)
- OAuth clients use 3-arg signature: (oauth_client, app_name, network_code=...)

Solution:
- Service account path (line 576): Use 2-argument signature
- OAuth path (line 596): Unchanged, uses 3-argument signature
- Matches GAM health check pattern (src/adapters/gam/utils/health_check.py:86)

Testing:
- Service account tenants: inventory sync now works
- OAuth tenants: unchanged, continues to work

Fixes adcontextprotocol#570
bokelley pushed a commit that referenced this pull request Oct 23, 2025
PR #570 was merged but inventory sync still fails for service account
authentication with error: 'Credentials' object has no attribute 'CreateHttpHeader'

Root Cause:
- google.oauth2.service_account.Credentials lacks CreateHttpHeader method
- AdManagerClient requires 2-arg signature: (credentials, network_code)
- OAuth clients use 3-arg signature: (oauth_client, app_name, network_code=...)

Solution:
- Service account path (line 576): Use 2-argument signature
- OAuth path (line 596): Unchanged, uses 3-argument signature
- Matches GAM health check pattern (src/adapters/gam/utils/health_check.py:86)

Testing:
- Service account tenants: inventory sync now works
- OAuth tenants: unchanged, continues to work

Fixes #570
EmmaLouise2018 pushed a commit that referenced this pull request Oct 24, 2025
PR #570 was merged but inventory sync still fails for service account
authentication with error: 'Credentials' object has no attribute 'CreateHttpHeader'

Root Cause:
- google.oauth2.service_account.Credentials lacks CreateHttpHeader method
- AdManagerClient requires 2-arg signature: (credentials, network_code)
- OAuth clients use 3-arg signature: (oauth_client, app_name, network_code=...)

Solution:
- Service account path (line 576): Use 2-argument signature
- OAuth path (line 596): Unchanged, uses 3-argument signature
- Matches GAM health check pattern (src/adapters/gam/utils/health_check.py:86)

Testing:
- Service account tenants: inventory sync now works
- OAuth tenants: unchanged, continues to work

Fixes #570
danf-newton pushed a commit to Newton-Research-Inc/salesagent that referenced this pull request Nov 24, 2025
danf-newton pushed a commit to Newton-Research-Inc/salesagent that referenced this pull request Nov 24, 2025
…ntextprotocol#571)

PR adcontextprotocol#570 was merged but inventory sync still fails for service account
authentication with error: 'Credentials' object has no attribute 'CreateHttpHeader'

Root Cause:
- google.oauth2.service_account.Credentials lacks CreateHttpHeader method
- AdManagerClient requires 2-arg signature: (credentials, network_code)
- OAuth clients use 3-arg signature: (oauth_client, app_name, network_code=...)

Solution:
- Service account path (line 576): Use 2-argument signature
- OAuth path (line 596): Unchanged, uses 3-argument signature
- Matches GAM health check pattern (src/adapters/gam/utils/health_check.py:86)

Testing:
- Service account tenants: inventory sync now works
- OAuth tenants: unchanged, continues to work

Fixes adcontextprotocol#570
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