GetSupportX
Portal sign-in docs
Portal sign-in guide

Shopify

For Shopify stores whose customers log in to a store account, with a developer to set it up.

Needs a developer

Before you start

In GetSupportX, open Settings → Help center & portal → Portal sign-in and switch on Sign in through your website. Answer What is your website built on? with Shopify.

Under 1 · Secret key, click Create secret key. Copy the key straight away: it is shown once. The code on this page needs it.

Copy the code from 2 · Add the code to your website: your callback URL is already filled in there. Copying the code from this page instead? Replace the whole https://<your-help-center>/portal/handoff address with the Callback URL Settings shows under For developers in step 2. Don’t build it by hand: it isn’t the same for every help center.

Steps

  1. Create an app in Shopify’s Dev Dashboard

    In the same Shopify organization as your store: Shopify only gives the app the token this code uses when the app and the store belong to the same organization. Give it the read_customers scope and install it on your store. (Apps can no longer be created directly in the Shopify admin.)

  2. Add an App Proxy to the app

    Prefix apps, subpath support, proxy URL https://<your-project>.vercel.app/api/support.

  3. Deploy the function below

    The example is a Vercel Function. It needs three environment variables: SHOPIFY_CLIENT_ID and SHOPIFY_CLIENT_SECRET (the app’s client ID and secret from the Dev Dashboard; the same secret checks the App Proxy signature), and GSX_SSO_SECRET (your secret key). There is no admin token to paste: the function asks Shopify for one with the client ID and secret (each lasts 24 hours) and reuses it until shortly before it expires.

  4. Set your sign-in link

    https://your-store.com/apps/support, with your store’s domain. You can link to the same address from your theme.

The code

api/support.js
// api/support.js — a Vercel Function behind a Shopify App Proxy.
// NEEDS A DEVELOPER: an app made in the Shopify Dev Dashboard, in the SAME
// organization as the store (Shopify only hands this kind of app an Admin API
// token for its own organization's stores), installed on the store, with:
//
//   1. Access scope read_customers.
//   2. App proxy → prefix "apps", subpath "support", proxy URL
//      https://<your-project>.vercel.app/api/support
//   3. Environment: SHOPIFY_CLIENT_ID and SHOPIFY_CLIENT_SECRET (the app's
//      client ID and secret — the secret also checks the proxy's signature),
//      and GSX_SSO_SECRET.
//   4. Theme link and your sign-in link:  https://your-store.com/apps/support
//
// Why not Liquid: a theme can compute a signature, but anyone with theme or app
// access could read the secret, and storefront pages can be cached.
import crypto from "node:crypto";

const CALLBACK = "https://<your-help-center>/portal/handoff";

// The portal page the customer was heading to (a ticket from an email, say),
// which the portal sends as ?gsx_return=. Only a plain path is passed on —
// GetSupportX checks it again before using it.
function returnPath(value) {
  return typeof value === "string" && value.startsWith("/") &&
    !value.startsWith("//") && !value.startsWith("/\\") ? value : "";
}

// Signs the customer's details with your SSO secret and sends them to the
// portal. Never cached: the link inside signs one person in.
function signedCallbackUrl(payload, back) {
  const secret = process.env.GSX_SSO_SECRET;
  if (!secret) throw new Error("GSX_SSO_SECRET is not set — paste your SSO secret into your environment.");
  const now = Math.floor(Date.now() / 1000);
  // jti: a one-time id, so this exact link can never be used twice.
  const body = { ...payload, iat: now, exp: now + 300, jti: crypto.randomBytes(16).toString("hex") };
  const b64 = Buffer.from(JSON.stringify(body), "utf8").toString("base64");
  const sig = crypto.createHmac("sha256", secret).update(b64).digest("hex");
  let url = CALLBACK + "?payload=" + encodeURIComponent(b64) + "&sig=" + sig;
  if (returnPath(back)) url += "&redirect=" + encodeURIComponent(back);
  return url;
}

function signInRedirect(payload, back) {
  return redirectTo(signedCallbackUrl(payload, back));
}

function redirectTo(url) {
  return new Response(null, { status: 302, headers: { Location: url, "Cache-Control": "no-store" } });
}

// Shopify signs every proxied request: drop "signature", sort "key=value"
// (multiple values joined with ","), concatenate, HMAC-SHA256 with the app secret.
function fromShopify(params) {
  const message = [...new Set(params.keys())]
    .filter((k) => k !== "signature")
    .map((k) => k + "=" + params.getAll(k).join(","))
    .sort()
    .join("");
  const expected = crypto.createHmac("sha256", process.env.SHOPIFY_CLIENT_SECRET).update(message).digest("hex");
  const given = params.get("signature") || "";
  return given.length === expected.length &&
    crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected));
}

// An Admin API token from Shopify's client credentials grant. It lasts 24
// hours, so it is kept in memory and fetched again shortly before it runs out.
let cachedToken = null;
async function adminToken(shop) {
  if (cachedToken && cachedToken.shop === shop && Date.now() < cachedToken.until) return cachedToken.token;
  const res = await fetch("https://" + shop + "/admin/oauth/access_token", {
    method: "POST",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    body: new URLSearchParams({
      grant_type: "client_credentials",
      client_id: process.env.SHOPIFY_CLIENT_ID,
      client_secret: process.env.SHOPIFY_CLIENT_SECRET,
    }).toString(),
  });
  const data = await res.json();
  if (!data?.access_token) throw new Error("Shopify gave no access token: " + (data?.error || res.status));
  const seconds = Math.max(60, Number(data.expires_in || 0) - 300); // renew 5 minutes early
  cachedToken = { shop, token: data.access_token, until: Date.now() + seconds * 1000 };
  return cachedToken.token;
}

export async function GET(request) {
  const params = new URL(request.url).searchParams;
  if (!fromShopify(params)) return new Response("Not from Shopify", { status: 401 });

  const shop = params.get("shop"); // your-store.myshopify.com
  const customerId = params.get("logged_in_customer_id");
  const back = returnPath(params.get("gsx_return"));
  if (!customerId) {
    // Guests log in to the store, then come back here (with the page they wanted).
    const here = "/apps/support" + (back ? "?gsx_return=" + encodeURIComponent(back) : "");
    return redirectTo("/account/login?return_url=" + encodeURIComponent(here));
  }

  // The proxy only says WHICH customer — ask Shopify for their email and name.
  const res = await fetch("https://" + shop + "/admin/api/2026-10/graphql.json", {
    method: "POST",
    headers: { "Content-Type": "application/json", "X-Shopify-Access-Token": await adminToken(shop) },
    body: JSON.stringify({
      query: "query($id: ID!) { customer(id: $id) { email displayName } }",
      variables: { id: "gid://shopify/Customer/" + customerId },
    }),
  });
  const customer = (await res.json())?.data?.customer;
  if (!customer?.email) return new Response("Customer not found", { status: 404 });

  return signInRedirect({
    externalId: "shopify:" + shop + ":" + customerId,
    site: "https://" + shop,
    legacyExternalId: String(customerId), // keeps customers an older snippet created
    email: customer.email,
    name: customer.displayName,
  }, back);
}

Every version of this code signs the same way. The protocol reference lists each field and rule, including the optional customer details (plan, phone and more) you can add.

Check it works

  1. Save your sign-in link

    In Settings → Help center & portal → Portal sign-in, enter it under 3 · Sign-in link (for example https://your-store.com/apps/support) and click Save. What is the sign-in link?

  2. Click Test sign-in

    Under Check it works. We open your link as a visitor who isn’t logged in. “Your sign-in link is live” means your link sent that visitor somewhere other than your homepage or the portal, and names the address. Check that address is your login page.

  3. Try it as a customer

    Log in to your website, then open your sign-in link. You should land in your portal, signed in. If not, Check it works lists the reason under recent failed sign-ins, and Troubleshooting says how to fix it.

Good to know

  • Why not theme code? A theme could work out the signature, but anyone with theme or app access could then read your secret key, and storefront pages can be cached.
  • The function checks that each request really came through Shopify’s App Proxy before it trusts the customer id in it.
  • Setting this up for a client’s store? Create the app in the Shopify organization the store belongs to. Shopify refuses this kind of token for a store outside the app’s organization.
  • Customers who aren’t logged in are sent to your store’s login page, then back.
  • No developer? You don’t need this. Customers already sign in to the portal with a link we email them.

Read next