Skip to content

Fix WPCOM API partner token validation for client credentials #2985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

budzanowski
Copy link
Collaborator

@budzanowski budzanowski commented Jun 25, 2025

Summary

Fixes WPCOM API health checks that are failing after switching from OAuth to client credentials in INTEGRA-48. The system incorrectly reports partner token as unhealthy, causing authorization status to be set to 'error' and blocking functionality.

Root Cause

  • WPCOM's /wc/partners/google/remote-site-status endpoint still validates OAuth-based partner tokens
  • Returns is_partner_token_healthy: false for client credentials authentication
  • Causes get_connected_status() to set WPCOM_REST_API_STATUS to 'error' instead of 'approved'
  • Results in broken UI states and blocked notifications/sync functionality

Changes Made

1. Fix partner token health check in AccountService::is_wpcom_api_status_healthy()

  • Inject is_partner_token_healthy: true when WPCOM returns false
  • Preserve existing logic for future compatibility
  • Add comment explaining temporary fix until INTEGRA-50 updates WPCOM API

2. Auto-set WPCOM_REST_API_STATUS to 'approved' in AccountService::get_connected_status()

  • Set status to 'approved' by default when not set (since authorization is automatic with client credentials)
  • Preserve code structure for future UI functionality that may allow user control
  • Fixes "NOT SET" status in debug interfaces

Impact

  • ✅ Unblocks NotificationsService functionality
  • ✅ Fixes Merchant Center account connection status
  • ✅ Resolves UI showing incorrect "Grant access" buttons
  • ✅ Ensures system works properly with client credentials from INTEGRA-48

Technical Notes

  • These are temporary compatibility fixes until INTEGRA-50 updates WPCOM API
  • Code preserved for future UI functionality allowing user management of these settings
  • Maintains all existing security and health checks except the problematic partner token validation

Test Plan

  • Verify Connection Test page shows 'approved' instead of 'NOT SET'
  • Confirm NotificationsService.is_ready() returns true
  • Test that Merchant Center account shows proper connected state
  • Ensure no "Grant access" buttons appear inappropriately
  • Verify product sync and notifications work correctly

Related Issues

  • Addresses: INTEGRA-51
  • Fixes issues introduced by: INTEGRA-48
  • Coordinates with: INTEGRA-50 (WPCOM API updates)

🤖 Generated with Claude Code

budzanowski and others added 2 commits June 25, 2025 15:52
- Fix partner token health check in is_wpcom_api_status_healthy()
  - Inject is_partner_token_healthy: true when WPCOM returns false
  - Preserves existing logic for future compatibility

- Auto-set WPCOM_REST_API_STATUS to 'approved' in get_connected_status()
  - Set status to 'approved' by default when not set
  - Preserves code structure for future UI functionality

These changes fix issues after switching from OAuth to client credentials
in INTEGRA-48, ensuring the system works properly with the new auth method.

Addresses: INTEGRA-51

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

Co-Authored-By: Claude <[email protected]>
- Mock is_wpcom_api_status_healthy to return true in test_get_connected_status_incomplete
- Update expected wpcom_rest_api_status to 'approved' instead of null
- Reflects new behavior where authorization is always approved with client credentials

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

Co-Authored-By: Claude <[email protected]>
Copy link

codecov bot commented Jun 25, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 66.2%. Comparing base (683dc35) to head (5d5b24c).
Report is 6 commits behind head on test/combined-branches.

Files with missing lines Patch % Lines
src/MerchantCenter/AccountService.php 60.0% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                    Coverage Diff                     @@
##             test/combined-branches   #2985     +/-   ##
==========================================================
- Coverage                      66.2%   66.2%   -0.0%     
- Complexity                     4828    4831      +3     
==========================================================
  Files                           490     490             
  Lines                         20539   20544      +5     
==========================================================
+ Hits                          13592   13595      +3     
- Misses                         6947    6949      +2     
Flag Coverage Δ
php-unit-tests 66.2% <60.0%> (-<0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/MerchantCenter/AccountService.php 93.5% <60.0%> (-0.6%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@budzanowski budzanowski self-assigned this Jun 25, 2025
@budzanowski budzanowski merged commit 2e43b21 into test/combined-branches Jun 25, 2025
12 checks passed
@budzanowski budzanowski deleted the integra-51-fix-wpcom-api-partner-token-validation-for-client branch June 25, 2025 16: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