pinterest-for-woocommerce
pinterest-for-woocommerce copied to clipboard
Token invalid reset procedure.
Changes proposed in this Pull Request:
Closes #993
Listen to API 401/403 responses, which may happen during user interaction with a plugin or when Pinterest for WooCommerce Action Scheduler tasks run.
In the case of the 401/403 response code, disconnect the user, reset the connection workflow (display landing page), stop feed generation and feed registration Action Scheduled actions, and show a notice about an action required.
Moving all found occurrences of the Base::make_request()
direct calls under APIV5
class.
Screenshots:
Detailed test instructions:
Action Scheduler 401 test.
- Connect to Pinterest.
- Go to https://github.com/woocommerce/pinterest-for-woocommerce/blob/bfe58e500b8738392d1adff4ddcada7bc6030af5/src/API/Base.php#L268
- Change it (add some characters after
Bearer
, e.g.
$request['headers']['Authorization'] = 'Bearer ***' . static::get_token()['access_token'];
- Go to WooCommerce - Status - Pending (actions).
- Force run
pinterest-for-woocommerce-handle-feed-registration
action. - Observe a Notice.
- Check that Pending section does not have
pinterest-for-woocommerce-handle-feed-registration
andpinterest-for-woocommerce-start-feed-generation
actions scheduled. - Go to Marketing - Pinterest and observe the Landing page instead of the Connection page.
- Observe the Notice above the Landing page.
User interaction test.
NOTE: Since the Pinterest for WooCommerce plugin has a React frontend application that calls corresponding REST APIs, the UX may seem a bit odd. 401 errors will occur on REST API calls, and we can not perform proper redirects without modifications to the plugin's communication layer. The page reload is required to observe the 401 handling results. We may adjust the frontend application soon after.
- Connect to Pinterest.
- Go to https://github.com/woocommerce/pinterest-for-woocommerce/blob/bfe58e500b8738392d1adff4ddcada7bc6030af5/src/API/Base.php#L268
- Change it (add some characters after
Bearer
, e.g.
$request['headers']['Authorization'] = 'Bearer ***' . static::get_token()['access_token'];
- Go to Marketing - Pinterest.
- Refresh the page and see the Landing page with the Notice above it.
P.S. 403 error test by changing the scope is impossible since we do not send the scope to Pinterest, which is encoded into the access token. Fake access tokens will always cause 401.
Changelog entry
Add - 401/403 Pinterest API error handling.