feat(shopify): OAuth (offline token) via a store-domain prompt - #526
Merged
Conversation
Replaces the manual custom-app token flow with a one-click OAuth grant.
Shopify's authorize endpoint is per-store but the runtime's
authorizationUrl(callbackUrl) hook doesn't know the store, so (like the
WhatsApp MCP) the hook points at our own /oauth/custom page which asks for
the shop domain, then drives the real Shopify grant and hands the mesh a
sealed credential.
- server/lib/token.ts: stateless crypto — HMAC-signed state + AES-256-GCM
sealed { shop, token } credential (so the Admin token never travels
readable through browser redirects) + Shopify callback HMAC verification.
- server/lib/oauth.ts: oauth hook (authorizationUrl/exchangeCode) and the
/oauth/custom + /oauth/shopify/callback route handlers. Offline token, no
refresh. Requested scopes trimmed to what a standard store can grant
(Plus/Payments-gated scopes excluded) and overridable via SHOPIFY_SCOPES.
- server/lib/client.ts: resolveCredentials opens the sealed credential
(both shop + token come from it); legacy raw-token + env-var paths kept.
- types/env.ts + app.json: drop the storeDomain config field and the token
auth block; refresh descriptions.
- deploy.ts / deploy.yml / SECRETS.md: wire SHOPIFY_CLIENT_ID,
SHOPIFY_CLIENT_SECRET, SHOPIFY_TOKEN_SECRET, SHOPIFY_SCOPES.
- README: rewrite setup/auth notes for OAuth.
Tests: 51 pass (token sign/seal, HMAC, route handlers, credential resolution).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The MCP now has no connection config: auth is OAuth and the store comes from the token. The Admin API version still defaults to DEFAULT_API_VERSION and can be overridden per deploy via the SHOPIFY_API_VERSION env var. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jul 28, 2026
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.
What
Replaces the Shopify MCP's manual custom-app token auth with a one-click OAuth grant (authorization code, offline token).
Why it needed a custom flow
Shopify's authorize endpoint is per-store (
https://{shop}.myshopify.com/admin/oauth/authorize), but the runtime'sauthorizationUrl(callbackUrl)hook doesn't know which store the user wants — so we can't build it up front. Following the WhatsApp MCP pattern, the hook points at our own/oauth/custompage, which asks the merchant for their shop domain and then drives the real Shopify grant, handing the mesh a sealed credential.Flow
authorizationUrl→ 302 to/oauth/custom?callback_url=…/oauth/customrenders a store-domain form → 302 to Shopify/admin/oauth/authorize(redirect_uriback to us, mesh callback signed intostate)/oauth/shopify/callback→ verify HMAC + state, exchange code for an offline token, seal{shop, token}, 302 back to the mesh callback with it ascodeexchangeCode({ code })→ validate and return the sealed credential as the connection's access tokenChanges
server/lib/token.ts— stateless crypto: HMAC-signed state + AES-256-GCM sealed{shop, token}credential (Admin token never travels readable through browser redirects) + Shopify callback HMAC verification.server/lib/oauth.ts— theoauthhook and the two custom route handlers. Offline token → norefreshToken. Requested scopes trimmed to what a standard store can grant (Plus/Payments-gated scopes excluded) and overridable viaSHOPIFY_SCOPES.server/lib/client.ts—resolveCredentialsopens the sealed credential (both shop + token come from it). Legacy raw-token + env-var dev paths kept for back-compat.types/env.ts+app.json— drop thestoreDomainconfig field and the tokenauthblock; refresh descriptions.scripts/deploy.ts/deploy.yml/SECRETS.md— wireSHOPIFY_CLIENT_ID,SHOPIFY_CLIENT_SECRET,SHOPIFY_TOKEN_SECRET,SHOPIFY_SCOPES.README.md— rewrite setup + auth notes.Deploy prerequisites (not code)
https://sites-shopify.deco.siteand redirecthttps://sites-shopify.deco.site/oauth/shopify/callback.SHOPIFY_CLIENT_ID,SHOPIFY_CLIENT_SECRET,SHOPIFY_TOKEN_SECRET(openssl rand -hex 32).SELF_URL/MESH_URLat runtime (same as the WhatsApp MCP) — needs confirming in staging.Testing
bun test— 51 pass (token sign/seal round-trips, tamper detection, Shopify HMAC, both OAuth route handlers, credential resolution incl. sealed + legacy paths, scope defaults + env override).tsc --noEmitclean for project files.🤖 Generated with Claude Code
Summary by cubic
Replaces manual token auth with a store‑domain prompted OAuth flow that issues a read‑only offline token and seals
{shop, token}as the connection credential. Drops all connection config (storeDomain,apiVersion), updatesregistry.jsoncopy, and keeps legacy token paths for dev/back‑compat.New Features
/oauth/custom+ Shopify callback; offline token; runtime wired with theoauthhook.SHOPIFY_SCOPES.2026-07; override per deploy withSHOPIFY_API_VERSION.Migration
SHOPIFY_CLIENT_ID,SHOPIFY_CLIENT_SECRET,SHOPIFY_TOKEN_SECRET(rotate to invalidate), optionalSHOPIFY_SCOPES.storeDomainfield,apiVersionfield, and the token auth block fromapp.json.SHOPIFY_STORE_DOMAIN+SHOPIFY_ACCESS_TOKENor a rawAuthorization: Bearer shpat_….Written for commit 735f84d. Summary will update on new commits.