Detect Jetpack JSON API module status before attempting wpcom-api auth#25
Open
Detect Jetpack JSON API module status before attempting wpcom-api auth#25
Conversation
The WordPress.com API probe returns "API calls to this blog have been disabled" for two different states: Jetpack connected but the JSON API module is off, and Jetpack installed but not connected at all. Without distinguishing these, the connect agent would send users through the full OAuth flow only for API calls to fail afterward. Check the self-hosted /jetpack/v4/connection endpoint when we get that error; the hasConnectedOwner field tells us which state we're in. In both cases, fall back to REST API + Application Password and let the user know why. Tested against test site in all three states: disconnected, connected with module off, and connected with module active.
22bfa72 to
600e1c6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The WordPress.com API returns the same error (
"API calls to this blog have been disabled") for two different states: Jetpack connected but JSON API module off, and Jetpack installed but not connected at all. The connect agent had no way to distinguish these, so it would send users through the full OAuth flow only for API calls to fail afterward.This adds a secondary check against the self-hosted
/jetpack/v4/connectionendpoint when we get that error. ThehasConnectedOwnerfield tells us which state we're in, so we can give the user an accurate message and fall back to REST API + Application Password.Test plan
Tested against a test site of mine in all three states:
hasConnectedOwner: false-> shows "Jetpack installed but not connected" message, falls back to REST APIhasConnectedOwner: true-> shows "JSON API module not active" message, falls back to REST API