Repository navigation
Connect with Fleetbase (OAuth) and automatic webhook registration - #2
Merged
Merged
Conversation
- Connect with Fleetbase: the setup wizard's connect step signs the merchant in to Fleetbase instead of asking for a pasted key. The store registers itself as a public PKCE client (POST /oauth/register, software_id fleetbase-woocommerce), the merchant approves it for an organization, and Fleetbase creates the store's API key (POST /oauth/v1/api-key), which is then saved exactly like a pasted key. Tokens are dropped, never revoked. Needs core-api 1.6.74 with fleetbase/core-api#327. Pasting a key still works. - Status updates are registered automatically through /v1/webhook-endpoints after any connect, kept in step when the URL is regenerated, and removed on disconnect. Deliveries must carry a valid X-Fleetbase-Signature while the plugin holds the endpoint's secret. When Fleetbase refuses the URL (localhost, private networks, older servers) the card shows why and the manual steps. - The sandbox admin password is generated into the gitignored .sandbox.env by scripts/seed-store.sh and read by the end-to-end setup; it is no longer hardcoded. - Tests for PKCE, the OAuth client, webhook signatures and registration.
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
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
Setup no longer asks the merchant to create and paste an API key, or to copy a webhook URL into the Fleetbase console.
Connect with Fleetbase
POST {host}/oauth/register,software_id=fleetbase-woocommerce, redirect{admin_url}admin-post.php?action=fleetbase_wc_oauth). Registration is idempotent and runs on every start.organization:read api-key:create,prompt=consent.POST {host}/oauth/v1/api-key, checks the key withorganizations/current, and saves it throughConnectionStore::save(), exactly as a pasted key is saved. The plugin keeps running on an API key; the OAuth tokens are dropped and never revoked, because revoking the grant expires the key. Removing the store under Connected apps in Fleetbase disconnects it.?fleetbase_oauth=<reason>and the wizard explains them in a sentence.Automatic status updates
Sync\WebhookRegistrarregisters the webhook URL with/v1/webhook-endpoints(core-api 1.6.74) for the order events the receiver acts on, adopting an existing endpoint for the same URL, and stores the endpoint's signing secret encrypted.X-Fleetbase-Signature(5 minute tolerance) as well as the URL token.fleetbase_wc_before_disconnectaction).Also fixed
scripts/seed-store.shgenerates the sandbox admin password into the gitignored.sandbox.env, and the end-to-end setup reads it. The password was still hardcoded onmain, and.sandbox.envwas not ignored.Depends on
fleetbase/core-api#327 (dynamic client registration and the
api-key:createscope), intorelease/v1.6.74.Test plan
composer lint,composer analyse(PHP 8.3 and the 8.1 config),pnpm lint:js,pnpm build./oauth/register(same client as a direct registration, so idempotent) and redirects to/oauth/authorizewith both scopes, S256 andprompt=consent; Fleetbase hands it to the console consent screen.fleetbase_oauth=access_denied; a replayed or forged state returnsstate_mismatch; a signed-out callback goes to the WordPress login; the existing connection is untouched by all of them.POST fleetbase/v1/webhook/registeragainst the local API stores "The url must be a public HTTP or HTTPS URL." and keeps the manual card.