Public apps and OAuth
An app in the App Store works for every store that installs it. The merchant sees what the app will be able to see and edit, approves it, and your app gets an Admin API token for that store. It's the OAuth authorization code grant, the way Shopify does it.
How an install works#
- 1Send the merchant to the store's authorize URLYour app asks for the access it needs, with a
stateto recognize the merchant when they come back. - 2The merchant approvesWeftstore shows the store, your app, what it will be able to see and edit, and its pricing. Signed-out merchants log in first.
- 3They come back to your redirect URL with a codeCheck the
hmacand thestatebefore anything else. - 4Swap the code for an access tokenFrom your server, with your client secret. Then call the Admin API with the token like any other app.
Installs from the App Store's Install button work the same way without the first step: the merchant approves the access your app declares in the partner dashboard and comes back to your first redirect URL with code, shop, timestamp and hmac, and no state. Check the hmac always, and the state only when your app started the install. Test on your store in the partner dashboard is the same install for your own stores while your app is unpublished. An app without a redirect URL opens in the admin instead.
Who can install: people with the Apps and API permission in the store whose own permissions cover what your app asks for, with a confirmed email address, on a plan that includes App Store apps. Until your app is published, only its developer can install it, and only on a store their own account owns: staff in someone else's store can't test your app there.
New to this? Build your first app goes through the whole install with a starter app you can run.
Asking for access#
https://example-store.weftgrid.store/admin/oauth/authorize?client_id=slc_6f1d0c4b…&scope=read_orders,write_products&redirect_uri=https%3A%2F%2Fapp.example%2Fauth%2Fcallback&state=6c2f9d1e8a| Parameter | What it is |
|---|---|
client_id | Your app's client ID, from the partner dashboard. |
scope | Comma-separated scopes, each one your app declares (a declared write_x covers read_x). It can be empty. |
redirect_uri | One of your app's redirect URLs, exactly as listed: scheme, host, port, path and query, character for character. |
state | A random value you keep with the merchant's session and check when they come back. Required. |
{shop} is the store's Weftstore address, like example-store.weftgrid.store, or its own domain. A request that fails a check (an unknown client ID, a redirect URL that isn't yours, a scope you don't declare, no state) shows an error page that names the problem, and nobody is redirected anywhere. The page the merchant approves on is valid for 60 minutes.
The redirect back#
https://app.example/auth/callback?code=Qm9vay1hLXBpY2t1cC…&shop=example-store.weftgrid.store&state=6c2f9d1e8a×tamp=1761390720&hmac=4b1d0e…| Parameter | What it is |
|---|---|
code | Single use, for 10 minutes. Swap it for a token right away. |
shop | The store's permanent Weftstore address. Send the token request there. |
state | Your state, unchanged. Refuse the request when it isn't the one you sent. An install that didn't start in your app (from the App Store, or Test on your store) has none. |
timestamp | When the redirect was made, in Unix seconds. Refuse old ones. |
hmac | HMAC-SHA256 of the other parameters, keyed with your client secret, in hex. |
To check hmac: take every query parameter except hmac, write each as key=value with % as %25 and & as %26 (and = as %3D in keys), sort them by key, join them with &, compute the HMAC-SHA256 with your client secret and compare in constant time. The same check works for embedded apps' URLs.
import crypto from "node:crypto";
const escape = (text, isKey) => {
const out = text.replace(/%/g, "%25").replace(/&/g, "%26");
return isKey ? out.replace(/=/g, "%3D") : out;
};
/** query: the request's URLSearchParams. secret: your app's client secret. */
export function validHmac(query, secret) {
const given = query.get("hmac") ?? "";
const message = [...query.entries()]
.filter(([key]) => key !== "hmac" && key !== "signature")
.map(([key, value]) => [escape(key, true), escape(value, false)])
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
.map(([key, value]) => `${key}=${value}`)
.join("&");
const expected = crypto.createHmac("sha256", secret).update(message, "utf8").digest("hex");
return given.length === expected.length && crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected));
}
// app.get("/auth/callback", (req, res) => {
// const query = new URL(req.url, "https://app.example").searchParams;
// if (!validHmac(query, process.env.STORELOOM_CLIENT_SECRET)) return res.sendStatus(400);
// …check state, then exchange query.get("code") for a token
// });import hashlib
import hmac
from urllib.parse import parse_qsl
def _escape(text: str, is_key: bool) -> str:
out = text.replace("%", "%25").replace("&", "%26")
return out.replace("=", "%3D") if is_key else out
def valid_hmac(query_string: str, secret: str) -> bool:
"""query_string: the raw query of the request, without the leading "?"."""
pairs = parse_qsl(query_string, keep_blank_values=True)
given = next((v for k, v in pairs if k == "hmac"), "")
parts = sorted(
((_escape(k, True), _escape(v, False)) for k, v in pairs if k not in ("hmac", "signature")),
key=lambda part: part[0],
)
message = "&".join(f"{k}={v}" for k, v in parts)
expected = hmac.new(secret.encode(), message.encode(), hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, given)
# Flask:
# if not valid_hmac(request.query_string.decode(), os.environ["STORELOOM_CLIENT_SECRET"]):
# abort(400)<?php
// $queryString: the raw query of the request ($_SERVER['QUERY_STRING']).
// parse_str() changes some keys, so the query is split by hand.
function valid_hmac(string $queryString, string $secret): bool {
$given = '';
$parts = [];
foreach (explode('&', $queryString) as $pair) {
if ($pair === '') continue;
[$key, $value] = array_pad(explode('=', $pair, 2), 2, '');
$key = urldecode($key);
$value = urldecode($value);
if ($key === 'hmac') { $given = $value; continue; }
if ($key === 'signature') continue;
$parts[] = [str_replace(['%', '&', '='], ['%25', '%26', '%3D'], $key), str_replace(['%', '&'], ['%25', '%26'], $value)];
}
usort($parts, fn ($a, $b) => strcmp($a[0], $b[0]));
$message = implode('&', array_map(fn ($p) => $p[0] . '=' . $p[1], $parts));
return hash_equals(hash_hmac('sha256', $message, $secret), $given);
}
// if (!valid_hmac($_SERVER['QUERY_STRING'], getenv('STORELOOM_CLIENT_SECRET'))) {
// http_response_code(400);
// exit;
// }require "openssl"
require "uri"
def valid_hmac?(query_string, secret)
pairs = URI.decode_www_form(query_string)
given = pairs.find { |key, _| key == "hmac" }&.last.to_s
escape = ->(text, is_key) { out = text.gsub("%", "%25").gsub("&", "%26"); is_key ? out.gsub("=", "%3D") : out }
message = pairs
.reject { |key, _| %w[hmac signature].include?(key) }
.map { |key, value| [escape.(key, true), escape.(value, false)] }
.sort_by(&:first)
.map { |key, value| "#{key}=#{value}" }
.join("&")
expected = OpenSSL::HMAC.hexdigest("SHA256", secret, message)
expected.bytesize == given.bytesize && OpenSSL.fixed_length_secure_compare(expected, given)
end
# Rails: head :bad_request unless valid_hmac?(request.query_string, ENV["STORELOOM_CLIENT_SECRET"])When the merchant cancels, they come back with error=access_denied and your state (no code, no hmac).
Getting the access token#
curl -X POST "https://example-store.weftgrid.store/admin/oauth/access_token" \
-H "Content-Type: application/json" \
-d '{ "client_id": "slc_6f1d0c4b…", "client_secret": "slcs_…", "code": "Qm9vay1hLXBpY2t1cC…" }'{
"access_token": "slat_Jx2v9QeL0pWmK4tR7yZb3nHs8dUfAa1c",
"scope": "read_orders,write_products"
}Send client_id, client_secret and code as JSON or as a form. Keep the token on your server like a password and send it in X-Storeloom-Access-Token. A new token replaces the store's previous one for your app. scope is what the merchant approved; requests outside it get 403.
A store that already installed your app can approve it again, for example to give it more access. It then comes back with a new code, the token you exchange it for replaces the old one, and the old one answers 401 from then on. A 401 on the Admin API therefore means the store uninstalled your app or approved it again: forget the token and start the install over.
| Status | error | When |
|---|---|---|
| 400 | invalid_request | client_id, client_secret or code is missing, repeated or too long. |
| 401 | invalid_client | No app has this client ID, or the client secret is wrong. |
| 400 | invalid_grant | The code isn't this store's or this app's, is older than 10 minutes, or was already used. |
| 429 | slow_down | Too many token requests from one address (30 a minute). Retry-After says when to try again. |
Errors come as { "error": "…", "error_description": "…" }.
Embedded apps#
An embedded app opens inside the Weftstore admin: your app URL loads in a frame under a bar with your app's name and an Open in new tab link. The URL carries shop, host (base64 of where the admin is), timestamp, locale, embedded=1 and an hmac made the same way as on the redirect. Apps that aren't embedded open in a new tab with the same parameters, without embedded.
https://app.example/admin?embedded=1&hmac=9c0a7f…&host=bG9jYWxob3N0OjMwMDAvYWRtaW4&locale=en&shop=example-store.weftgrid.store×tamp=1761390720The frame is sandboxed with allow-scripts allow-forms allow-same-origin allow-popups allow-downloads: your pages can't navigate the admin itself. Serve them over https from your own domain. While you build, a Weftstore that runs on your machine over http can frame http://127.0.0.1 and http://localhost addresses too: browsers block an http frame only inside an https page.
Your pages also have to say that the admin may frame them. Every other page of Weftstore refuses to be framed, and so does yours unless you allow it. Send this header with every page that loads in the frame:
Content-Security-Policy: frame-ancestors https://store.weftgrid.comhttps://store.weftgrid.com is the address of this admin: it is the host parameter decoded, with its scheme. Don't send X-Frame-Options, which many frameworks add by default: it can say "never" or "only my own site", not "this one other site", and your pages would be refused in the admin. An app that works on more than one Weftstore can build the value from the signed host parameter, as the starter app does:
// Inside the admin the app sits in a frame, and only the admin may frame it. The signed `host` value says where the
// admin is (base64 of "<address>/admin"). Don't send X-Frame-Options: it can't name another site.
const framed = q.get("embedded") === "1";
const adminAddress = Buffer.from(q.get("host") ?? "", "base64url").toString("utf8").split("/")[0];
const headers = { "Content-Security-Policy": isShop(adminAddress) ? `frame-ancestors ${SHOP_SCHEME}://${adminAddress}` : "frame-ancestors 'none'" };Charging merchants#
Paid apps create a monthly charge with POST /recurring_application_charges.json and send the merchant to its confirmation_url. The merchant approves or declines it and comes back to your return_url with charge_id; read the charge to see which. An approved charge is billed on the store's Weftstore invoice after its free trial, until you cancel it or the app is uninstalled. Approving a new charge cancels your app's current one. Charges nobody answers expire after 48 hours. Every change sends app_subscriptions/update to your app.
Storefront scripts#
With write_script_tags, your app can load up to 10 scripts on the store's pages with the script tags endpoints. They load when shoppers are on the store's own address (its subdomain or domain), never on the platform's preview paths, and they're removed when the app is uninstalled.
A script's URL must be https. A Weftstore that runs as a development server over plain http also takes http://localhost, http://127.0.0.1 and *.localhost addresses, so you can build without a tunnel; a hosted one refuses them with must be an https URL. Adding the same URL twice is refused with src: ["has already been added"], so look for it first with GET /script_tags.json?src=….
When a store uninstalls your app#
- Its open charges are cancelled (
app_subscriptions/update), thenapp/uninstalledis sent with the store as its payload. Subscribe to both with POST /webhooks.json. If your server doesn't answer with a 2xx,app/uninstalledis tried again on the usual schedule. - Then the token stops working, and the app's webhooks and storefront scripts are removed. Calls with the old token answer 401.
- 48 hours later
shop/redactis sent to your privacy webhook URL: erase what you kept about the store. If the store installs your app again before then, it is cancelled. See Uninstall and privacy messages and Privacy webhooks. - Webhooks to installed apps are signed with your client secret, as described in Verifying signatures. Rotating the secret in the partner dashboard updates every store at once.
curl -X POST "https://store.weftgrid.com/api/admin/2026-10/webhooks.json" \
-H "X-Storeloom-Access-Token: $STORELOOM_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "webhook": { "topic": "app/uninstalled", "address": "https://app.example/hooks/uninstalled" } }'