Choose an option
Use the broker pattern when:- Your integration is installed by each operator on infrastructure you don’t control (their WordPress site, browser, server, or laptop).
- You need access to operator data beyond simple read-only, public information.
- You want a single place to rotate credentials, revoke individual installations, and monitor usage.
- You need to keep the Stora
client_secretout of distributed plugin code, but you cannot operate a full broker that stores tokens and proxies every API call. - Your plugin can protect Stora access and refresh tokens on each operator’s infrastructure.
- You accept weaker revocation, observability, and compromise isolation than the broker pattern provides.
A hosted Shopify app usually uses the standard Authorization Code flow because the app backend is operated by the app developer and can act as the confidential OAuth client. Do not put Stora credentials or tokens in Shopify theme code, app extensions, or other client-side/distributed code. Route those calls through a backend you host.
Option 1: Broker pattern (recommended)
The broker pattern is the preferred option for public plugins. It keeps Stora tokens and OAuth credentials on infrastructure you control, and gives you one place to revoke installations, monitor usage, and handle refresh-token rotation.Architecture
The broker pattern splits responsibility across three actors. Your distributed integration code runs inside an environment you don’t control — it holds no Stora credentials. Your broker is a backend service you host — it holds your Storaclient_id and client_secret, stores each operator’s access and refresh tokens, and is the only thing Stora sees on the other end of OAuth. Stora issues exactly one confidential OAuth application to you, regardless of how many installations of your integration exist.
Connection flow at a glance
API call flow at a glance
Why the broker doesn’t hand Stora tokens to the plugin
It’s tempting to skip the broker’s own token layer and just forward Stora’saccess_token and refresh_token to the plugin. Doing so re-creates the problems the broker exists to avoid:
- Refresh-token theft persists. Stora’s refresh tokens are long-lived bearer credentials. Once exfiltrated from a plugin’s database or backup, they work until revoked.
- Revocation requires reconnection. Without a broker-issued token, stopping an installation requires revoking its Stora access and refresh token pair. That installation must reconnect. Other installations are affected only if they share the same pair.
- You lose scope narrowing. Broker-issued tokens can be narrower than the upstream OAuth grant. Raw Stora tokens cannot.
- You lose observability. Direct plugin → Stora calls bypass your broker’s logs, metrics, and rate limiting.
- Refresh rotation gets messy. Stora rotates refresh tokens on every use; with plugin-held tokens, every rotation has to be pushed back to each installation.
- The
client_secretis irrelevant after exfiltration. Attackers use stolen tokens directly — they don’t need to mint new ones.
client_secret in the plugin. Encrypt tokens at rest. Review the limitations in Alternatives considered. Encryption at rest protects against database dumps, but not against remote code execution or a malicious sibling plugin.
Connecting an operator
Before you can make API calls on behalf of an operator, the operator’s installation needs to go through the Authorization Code flow once. All three ofclient_id, client_secret, and the redirect_uri belong to your broker — the plugin never sees them. The flow below shows what your broker implements.
Create a test partner application in the Developer Portal and configure its redirect URI to point at your broker, for example
https://broker.yourcompany.com/stora/callback. Copy the client ID and reveal the client secret once, then store them on your broker. After approval, use the separate live application’s credentials for production. See Partner app credentials for the test and live setup.1
Plugin starts the connection
The operator clicks Connect to Stora in your plugin’s UI. Verify that the operator is authorised to connect this installation and protect this action against CSRF. Store a connection-attempt identifier in the operator’s session.From the plugin’s backend, create a connection attempt through an authenticated HTTPS request to your broker. Use the installation authentication you established during registration. Keep reusable credentials in request headers, not browser URLs.Bind the attempt to the installation, the session’s connection-attempt identifier, and a previously registered plugin callback URL. The broker returns an unpredictable, short-lived, single-use The code identifies this connection attempt only. It is not an installation credential or an API token. Exclude connection codes from logs and use a restrictive referrer policy on callback pages.
connect_code. Redirect the browser to:2
Broker redirects to Stora
The broker validates and atomically consumes the The
connect_code. Reject missing, expired, or reused codes. Create a fresh state value and bind it to the broker’s browser session and the stored connection attempt, including its installation and registered callback URL. Store it with a short expiry, then redirect the operator’s browser to Stora:state parameter is not optional for a broker: it prevents CSRF on the callback and lets you correlate the returning code with the right installation. Bind it to the initiating browser session as described in the Authorization Code walkthrough.3
Operator approves in Stora
The operator logs in to their Stora BackOffice (if not already) and approves the requested scopes. Stora redirects back to your broker’s callback with a one-time code:
4
Broker exchanges the code for tokens
Validate and consume the state before exchanging the code. Recover the Response:
install_id associated with the validated state. Then exchange the code at Stora’s token endpoint, authenticating with your client_secret:5
Broker stores tokens and returns to the plugin
Store the Do not include a broker token, installation secret, or Stora token in this URL. Do not accept an arbitrary callback URL from the browser.
access_token, refresh_token, and expires_at in your broker’s database, keyed by install_id. Generate an unpredictable, short-lived, single-use completion_code bound to the installation and the original connection attempt. Redirect to the plugin callback registered for that attempt:6
Plugin exchanges the completion code
Verify that the callback belongs to the operator session that started the connection. From the plugin’s backend, send the
completion_code and the stored connection-attempt identifier to the broker in an authenticated HTTPS request.The broker verifies the installation authentication, code expiry, and binding to the installation and connection attempt. Reject missing, expired, mismatched, or reused codes. Atomically consume the code before returning a broker-scoped token in the server-to-server response.Store the broker token on the plugin’s backend. It authenticates subsequent API calls to your broker. Stora’s access and refresh tokens remain on your broker. Clear the pending connection attempt and redirect the browser to a success page without the completion code in its URL.Making API calls
Once connected, the plugin makes requests to your broker, the broker translates them into Stora API calls using the storedaccess_token, and returns the response to the plugin. The broker is responsible for refreshing expired tokens silently and for surfacing a “reconnect required” signal when refresh fails.
The happy path
The plugin calls your broker. Authenticate the plugin with the broker-scoped token you issued during the connect flow:expires_at, refreshes if needed (see below), and proxies the request to Stora:
Refreshing tokens
Stora access tokens expire after 2 hours. When the storedexpires_at is within a small buffer of now (e.g. 5 minutes), refresh before making the call:
access_token and a new refresh_token. The previous refresh token is revoked immediately. Your broker must atomically update both values, or the next refresh will fail.
When refresh fails
A400 from the Stora token endpoint with "error": "invalid_grant" means the grant is no longer valid — usually because the operator disconnected your integration in Stora BackOffice. You cannot recover this without the operator going through the connect flow again.
The broker should: mark the installation’s tokens as revoked locally, return a well-defined error to the plugin (e.g. 401 Unauthorized with a body like {"error":"stora_reconnect_required"}), and let the plugin prompt the operator to reconnect.
Rate limits
Stora applies rate limits per operator (10 req/s, 60 req/min — see rate limiting). Your broker adds no rate-limit protection by default; a429 from Stora propagates back to the plugin. Consider short request coalescing (same plugin, same endpoint, same operator, within the same second) if your plugin is chatty.
Disconnecting and reconnecting
Operators need to offboard cleanly, re-grant access after revocation, and occasionally switch which Stora account they’ve connected — without uninstalling the plugin. Your plugin’s settings UI must expose Disconnect and Reconnect actions, and the broker must back them with the logic below.Disconnect
The plugin’s settings UI exposes a Disconnect button. When the operator clicks it, the plugin calls a disconnect endpoint on your broker — authenticated with the broker token — and your broker:- Calls Stora’s
POST /oauth2/revokewith the stored access token and your OAuth client credentials. - Deletes the stored Stora tokens and the broker token for this installation.
- Returns
204 No Contentto the plugin.
Reconnect
The plugin’s settings UI also exposes a Reconnect button, which redirects the operator back through your existing connect entry point. The broker overwrites the installation’s stored tokens on the next successful callback — no new endpoint required. Expose Reconnect even while the current tokens are still valid. Operators use it to re-grant expanded scopes when your integration adds a new feature, or to switch to a different Stora account without a reinstall.On plugin uninstall
The integration should fire the same disconnect flow automatically when the operator removes it from their host, using whatever uninstall or deprovisioning hook the platform exposes — for example WordPress’sregister_uninstall_hook, or Shopify’s app/uninstalled webhook for hosted Shopify apps.
Treat uninstall hooks as a hygiene layer, not a replacement for the explicit Disconnect action. Some platforms don’t fire them reliably: a user who deletes a WordPress site wholesale never triggers plugin uninstall hooks, and webhook delivery can fail on any hosted platform. The explicit Disconnect action plus Stora-side revocation remains the source of truth.
What your broker is responsible for
The broker is a piece of infrastructure you own and operate. At minimum, plan for the following.Plugin-to-broker authentication
Stora authenticates your broker viaclient_secret. Your broker needs its own way to authenticate plugin installations. A common pattern: the plugin generates a long random value at activation time, registers it with the broker (HTTPS call keyed by install URL + admin email), and uses it as a bearer token on subsequent calls. Bind each token to one installation so a token stolen from one site can’t be used to impersonate another. HMAC-signing requests with a per-install secret is a stronger alternative.
Token storage and rotation
Storeaccess_token, refresh_token, and expires_at per installation. Refresh tokens rotate on every use — the previous one is revoked the instant Stora returns a new one. Write the new refresh_token to your database before you return the response to whoever triggered the refresh, and serialise refresh attempts per installation so two parallel workers can’t race. Encrypt tokens at rest; the column on your broker’s database is as sensitive as your Stora client_secret.
Per-installation kill switch
Because the broker mints its own plugin-facing tokens, you can cut off a single installation without touching Stora: invalidate the broker token locally and the plugin starts receiving your reconnect error on every call. This is the fastest response to a compromised installation — no Stora support ticket, no scope re-negotiation, no impact on other installations.Monitoring and abuse detection
Log every call that passes through the broker withinstall_id, endpoint, and status code. Basic alerts to set up: sustained 429 rates per installation (indicates a runaway plugin), sustained 4xx rates (indicates a broken installation or probing), sudden growth in call volume from a single installation, and anything that looks like credential-stuffing against your own /connect endpoint. Ship these to whatever you already use — you don’t need anything Stora-specific.
Disconnect and reconnect endpoints
Expose routes the plugin can call to trigger Disconnect (broker revokes tokens at Stora and wipes local state) and Reconnect (broker redirects back through the connect flow). Wire the same revoke-and-discard path into the plugin’s platform-specific uninstall hook as best-effort hygiene.Option 2: Authorization proxy (lighter alternative)
The authorization proxy is a lighter alternative to the broker pattern. It keeps your Storaclient_secret on infrastructure you control, but it does not keep Stora tokens out of the plugin. The plugin installation — for example a WordPress site — stores the operator’s Stora access_token and refresh_token, and calls the proxy whenever it needs to exchange an authorization code or refresh a token.
How the authorization proxy works
The plugin backend first verifies that the operator can connect this installation and protects the connect action against CSRF. Create a single-usewp_state value and store it in the operator’s plugin session. Through an authenticated HTTPS request, register a connection attempt with the proxy. Bind it to the installation, wp_state, and a registered HTTPS callback URL. The proxy returns a short-lived, single-use connect_code for the browser redirect. Never send installation credentials in browser URLs.
When the browser presents connect_code, the proxy validates and atomically consumes it. Create an unpredictable OAuth state value bound to the proxy’s initiating browser session and the stored connection attempt. Store it with a short expiry, then redirect to Stora. A signed value alone does not establish this browser-session binding.
On callback, validate and atomically consume OAuth state before issuing code_context or forwarding the authorization code. Reject missing, mismatched, expired, or reused state. Create a signed, short-lived code_context bound to the authorization code and connection attempt. Redirect only to the registered plugin callback, including the code, code_context, and the original wp_state. Exclude these values from logs and use a restrictive referrer policy on callback pages.
The plugin validates and consumes wp_state against its initiating operator session before requesting tokens. Reject callbacks that do not match that session.
The plugin then calls the proxy server-to-server to exchange the code for Stora access and refresh tokens. The server-to-server call must authenticate the plugin installation, for example with an Authorization header or HMAC signature. The plugin stores the returned tokens locally, but never calls Stora’s token endpoint directly. When the access token expires, the plugin sends the stored refresh token to the proxy; the proxy authenticates to Stora with the partner client_secret, performs the refresh, and returns the rotated tokens for the plugin to replace locally.
The code_context is not a replacement for the Stora authorization code or session-bound state. It binds the code to the stored connection attempt, plugin installation, and callback URL. The proxy retains short-lived connection and replay-prevention records, but does not store the plugin’s Stora tokens between requests.
You can implement code_context as a signed JWT/JWS or any equivalent authenticated token format. The payload should include the authorization code hash, connection-attempt identifier, installation identifier, callback URL, and short expiry. Sign it with a proxy-only secret. Do not put the Stora client_secret or access/refresh tokens in code_context.
/token is called, authenticate the installation. Verify the code_context signature and expiry, then match its connection_id, install_id, callback URL, and code hash against the stored attempt. Atomically mark the token-exchange attempt as consumed before exchanging the code with Stora. Reject expired, mismatched, or reused attempts.
The diagram below uses WordPress as the example plugin host.
Authorization proxy trade-offs
Compared with the broker pattern, the authorization proxy removes the need to store per-installation Stora tokens on your backend. You still need short-lived connection records, browser-session binding, and single-use validation. Signedstate and code_context values do not remove those requirements.
The trade-off is that Stora tokens now live in the plugin installation. A compromised WordPress database, backup, admin account, server, or sibling plugin can expose the operator’s Stora tokens. You also lose the broker’s per-installation kill switch, API-level observability, rate limiting, and scope narrowing. Use this pattern only when that risk is acceptable, and document the token-storage responsibility clearly for operators.
Alternatives considered
You don’t need to read this section to build the integration. It exists for partners who want to understand why we recommend the broker pattern over the alternatives the OAuth 2.0 spec technically allows.Why not a public client with PKCE?
Why not a public client with PKCE?
PKCE protects authorisation codes from interception during the redirect. It does not protect OAuth tokens after they’re issued. For a plugin distributed to many operators, the consequences are:
- Tokens live on the operator’s infrastructure.
wp_optionsis plaintext; other sensitive values in the same table get exfiltrated together in DB dumps, backups copied to staging, and compromised-plugin incidents. - No client authentication. A public
client_idcan be copied into any application. PKCE binds a code to a device but proves nothing about who the client is. A phishing app reusing yourclient_idpresents the real Stora consent screen with your branding. - Refresh tokens are long-lived bearer credentials. Once out of the operator’s database they work until revoked. Rotation shrinks the window; it doesn’t close it.
- Loose redirect URIs. Thousands of installations mean either wildcard redirect URIs (vulnerable to subdomain takeover) or Dynamic Client Registration (see below).
- No abuse isolation. Revoking the public
client_idbreaks every installation simultaneously. - No consent phishing protection. An attacker can complete the flow with your
client_idsince there’s no secret to prove identity.
Dynamic Client Registration (RFC 7591)
Dynamic Client Registration (RFC 7591)
DCR would let each plugin installation register its own
client_id (still public, still PKCE) at install time. Each site then has its own OAuth client record on Stora’s side, which solves the redirect-URI and abuse-isolation problems.Stora does not currently support Dynamic Client Registration. If you have a use case that specifically requires it, get in touch — we prioritise based on partner demand. DCR alone doesn’t solve the token-storage problem (tokens still live in wp_options); it mainly simplifies the consent and redirect-URI side of operating many public-client installations.If you insist on sharing Stora tokens with the plugin
If you insist on sharing Stora tokens with the plugin
We understand the broker pattern adds operational overhead. If you decide to let the plugin store Stora access and refresh tokens, use the authorization proxy shape above. Do not put the Stora
client_secret in the plugin, and do not have the plugin call Stora’s token endpoint directly. The plugin should receive the authorization code in its callback, then call your proxy to exchange the code or refresh token. Your proxy authenticates to Stora with the client_secret and returns the resulting tokens to the plugin.At minimum, do the following:- Keep the
client_secretproxy-side. The proxy exists to protect the confidential OAuth client credentials. The plugin should only ever see the authorization code,code_context, access token, refresh token, expiry, and the plugin-to-proxy credential you design. - Bind OAuth state to the initiating browser session. Register the connection attempt through an authenticated plugin-backend request. Use a registered HTTPS callback URL. Validate and atomically consume session-bound OAuth state before forwarding the authorization code. Validate and consume the plugin’s session-bound
wp_statebefore requesting tokens. A signature alone is not sufficient. - Validate
code_contextand prevent replay. Bind the signed, expiring context to the authorization code hash, connection attempt, installation, and callback URL. Authenticate the installation and atomically consume the token-exchange attempt before calling Stora. Reject expired, tampered, mismatched, or reused values. - Authenticate plugin-to-proxy calls. The
/tokenand/refreshendpoints still need plugin authentication, such as anAuthorizationheader with an install-time shared secret or HMAC-signed requests. Do not pass that secret through browser redirects or query strings. Otherwise anyone with a code or refresh token can ask your proxy to use yourclient_secretfor them. - Encrypt tokens at rest. WordPress core stores
wp_optionsvalues as plaintext. Google Site Kit’sData_Encryptionis the de-facto reference implementation — AES-256-CTR with a key derived fromLOGGED_IN_KEYinwp-config.php. Most major plugins (Jetpack, WooCommerce Stripe, Mailchimp for WooCommerce) don’t encrypt at all; doing so puts you ahead of the ecosystem default. - Understand what encryption buys you. It only mitigates stolen SQL backups, misconfigured phpMyAdmin, read-only DB leaks, and compromised noisy neighbours on shared MySQL. It does not mitigate a compromised WordPress admin, an RCE on the host, a malicious sibling plugin, or a
wp-config.phpleak — in all those cases the key is on the same box. - Narrow your scopes aggressively. Request only what the plugin genuinely needs. Every scope you request is a scope an attacker inherits.
- Rotate refresh tokens through the proxy and persist the replacement. Stora rotates refresh tokens on every successful refresh. The plugin must send the current refresh token to the proxy, the proxy must refresh with the
client_secret, and the plugin must atomically replace both the access token and refresh token it has stored. - Revoke the installation’s Stora token pair to stop access. Without a broker-issued token layer, disabling the plugin’s proxy credential alone does not invalidate Stora tokens it already holds. Revoke its access and refresh token pair. Other installations are affected only if they share that pair.
client_secret; it does not remove the plugin host from the Stora token trust boundary. The broker pattern does, which is why we recommend it for anything touching customer PII, payments, contracts, access control, or other sensitive data.Next steps
You now have the OAuth side built. Before going live, also review:Partner approval checklist
Review OAuth, scopes, Timeline Events, webhooks, disconnect behavior, and public plugin requirements before you submit.
Rate limiting and backoff
Per-operator limits apply. Your broker or plugin must handle 429s, depending
on the pattern.
Webhooks
React to Stora events instead of polling. Your broker or proxy receives them
on a single URL.
Authentication reference
Full details on OAuth flows, token exchange, and token refresh.