App proxy
Serve a page or an API on the store's own address from your server, and check that each request comes from Tanqory.
An app proxy puts a path of the store's own address, such as https://example-store.mytanqory.com/apps/book, in front of your server. A shopper's browser calls the store; Tanqory adds who the store and the shopper are, signs the request, sends it to your server and returns your answer. Your page can call it with fetch from a theme app embed, with no cross-origin setup.
Set it up
In the partner dashboard open your app's Configuration, turn on Use an app proxy and fill in:
| Field | Value |
|---|---|
| Prefix | a, apps, community or tools |
| Subpath | 1 to 30 letters, digits, _ or -; not admin, services, password or login |
| Proxy URL | your server's https address, for example https://booking.example.com/proxy |
Turning the proxy on adds the write_app_proxy scope to what the app asks for. Then select Save version. A request to /<prefix>/<subpath>/rest/of/path goes to <Proxy URL>/rest/of/path, with the shopper's query string.
What your server receives
Tanqory adds these five query parameters to every request, and drops any parameter of the same name that the shopper sent:
| Parameter | What it contains |
|---|---|
shop | the store's address on Tanqory, for example example-store.mytanqory.com |
logged_in_customer_id | the signed-in shopper's customer id in this store (the last part of its Admin API id gid://tanqory/Customer/<id>), or empty when nobody is signed in |
path_prefix | /<prefix>/<subpath>, for example /apps/book |
timestamp | when Tanqory sent the request, in Unix seconds |
signature | the hex HMAC-SHA256 of the other parameters, keyed with your client secret |
Of the shopper's request headers, only Accept, Accept-Language, Content-Type, User-Agent and X-Forwarded-For are passed on. Cookies are not, and Tanqory adds no headers of its own: no X-Tanqory-Shop-Domain here. The store is the shop parameter. (X-Tanqory-Shop-Domain is a header of webhook deliveries, with the same value as shop.)
Check the signature
Build the message from every parameter except signature: for each name, name=value, with the values of a repeated name joined by ,. Sort these strings and join them with nothing between them. The hex HMAC-SHA256 of that message, keyed with your client secret, must equal signature. Compare in constant time and refuse an old timestamp.
import { createHmac, timingSafeEqual } from 'node:crypto';
// query: the URLSearchParams of the request as your server received it.
export function proxyRequestIsFromTanqory(query, clientSecret, maxAgeSeconds = 300) {
const byName = new Map();
for (const [k, v] of query) if (k !== 'signature') byName.set(k, [...(byName.get(k) ?? []), v]);
const message = [...byName].map(([k, vs]) => `${k}=${vs.join(',')}`).sort().join('');
const expected = Buffer.from(createHmac('sha256', clientSecret).update(message).digest('hex'));
const given = Buffer.from(query.get('signature') ?? '');
const fresh = Math.abs(Date.now() / 1000 - Number(query.get('timestamp'))) <= maxAgeSeconds;
return fresh && given.length === expected.length && timingSafeEqual(given, expected);
}import hashlib, hmac, time
from urllib.parse import parse_qsl
# query_string: the raw query string of the request, as your server received it.
def proxy_request_is_from_tanqory(query_string: str, client_secret: str, max_age_seconds: int = 300) -> bool:
by_name: dict[str, list[str]] = {}
signature = ""
for k, v in parse_qsl(query_string, keep_blank_values=True):
if k == "signature":
signature = v
else:
by_name.setdefault(k, []).append(v)
message = "".join(sorted(f"{k}={','.join(vs)}" for k, vs in by_name.items()))
expected = hmac.new(client_secret.encode(), message.encode(), hashlib.sha256).hexdigest()
ts = next((vs[0] for k, vs in by_name.items() if k == "timestamp"), "0")
fresh = abs(time.time() - int(ts or 0)) <= max_age_seconds
return fresh and hmac.compare_digest(expected, signature)Answer 401 when the check fails. While a rotated client secret has not been revoked, Tanqory signs with the old one (Secrets).
Your answer
- Up to 5 MB, within 10 seconds, with at most 5 redirects. Your server must be on a public address.
Set-Cookie,Server,X-Powered-By,Date,Pragma, connection headers and your ownX-Tq-*headers are removed. Without aCache-Controlof your own the answer getsprivate, no-store.- A
Content-Typeofapplication/liquidis refused: send HTML or JSON.
When no installed app owns the path, or the installation does not hold write_app_proxy, the shopper gets 404 with X-Tanqory-App-Proxy: none. When your server cannot be reached or breaks a limit, they get 502 with X-Tanqory-App-Proxy: failed:<why>.