TL;DR: If you use the Node/Remix template, session-token verification, token exchange, CSP, and iframe retry are handled for you - which means you can ship an embedded app without ever learning how the trust boundary works. I built one on a Rust/Axum backend with plain React Router and no Shopify npm packages, and these are the pieces I had to get right by hand. None of it is exotic, but every item is a place to be subtly wrong.
I recently shipped an embedded Shopify admin app (a bundle editor) with App Bridge loaded from the CDN, Polaris web components, and a Rust backend. Architecturally the admin app is a client-rendered React Router SPA - no SSR, no Node at runtime. Axum serves the static bundle and the API from one Rust binary. There's no shopify-app-remix/shopify-app-react-router, no @shopify/app-bridge-react, and no @shopify/polaris npm package.
The template is genuinely good, and I'll say below when I'd still reach for it. But going without it forced me to understand the auth model, and I think that's worth writing down.
The two tokens people conflate
There are two different tokens in an embedded app, and mixing them up is the root of a lot of confusion:
| Token | Where it comes from | Lifetime | What it's for |
|---|
| ID token (session token) | shopify.idToken() from App Bridge | ~1 minute | Proving this request came from an authenticated merchant session |
| Offline access token | Your backend exchanges the ID token with Shopify | ~1 hour (with a one-time refresh token) | Calling the Admin API from your backend |
The ID token is not an Admin API token. Don't store it, don't use it for Admin API calls, and don't treat it as a session. Your backend verifies it, then exchanges it for an offline access token.
Verifying the ID token
App Bridge v4 intercepts the global fetch and adds the ID token as Authorization: Bearer … for requests to your app's domain (and subdomains), plus Accept-Language. So on the frontend, plain fetch('/api/...') is already authenticated. The backend's job is to verify that JWT before trusting anything in it.
The checklist, straight from Shopify's docs:
- Signature is valid HS256, keyed by your app's client secret
aud equals your app's client IDexp is in the future (and nbf is in the past)iss and dest hostnames match
That last one is the one people skip. dest is your shop identity - it's tempting to read it and use it as a database key, but only after you've confirmed it's a real store host, not just a string that happens to end in .myshopify.com.
The core of my Rust verification:
let mut validation = Validation::new(Algorithm::HS256);
validation.set_audience(&[api_key]); // aud must equal the client id
validation.validate_exp = true;
validation.validate_nbf = true; // Shopify's checklist wants nbf enforced too
validation.leeway = 5; // small clock-drift allowance
let data = decode::<Claims>(
token,
&DecodingKey::from_secret(api_secret.as_bytes()),
&validation,
)?;
// dest and iss must resolve to the same *.myshopify.com host
if store_host(&data.claims.dest) != store_host(&data.claims.iss) {
return Err(/* 401 */);
}
let shop = store_host(&data.claims.dest); // now safe to key the session on
The store_host helper is deliberately strict: it strips the scheme, rejects anything with embedded credentials (@) or a port (:), requires the exact <handle>.myshopify.com shape, and rejects a bare myshopify.com or evil-myshopify.com. Without those checks, dest is attacker-influenced input. The signature makes forgery infeasible, but the claim still has to be a real Shopify store URL before you key rows on it.
Return a 401 (not 500) when this fails. Missing or expired tokens are routine, not server faults.
Exchanging the ID token for an Admin API token
Once verified, exchange it for an expiring offline access token:
POST https://{shop}.myshopify.com/admin/oauth/access_token
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
subject_token=<the verified ID token>
subject_token_type=urn:ietf:params:oauth:token-type:id_token
requested_token_type=urn:shopify:params:oauth:token-type:offline-access-token
expiring=1
Two details that cost me time:
expiring=1 matters for public apps. Non-expiring offline tokens are legacy. The refreshed access token lives ~1 hour, and the refresh token is one-time use, so refresh a few minutes before expiry rather than on every request.- Don't use the ID token as your stored credential. Exchange it, store the offline token, and refresh it. If you're migrating an older install, re-exchanging the session ID token is also how you cycle a legacy non-expiring token onto the expiring model.
CSP / frame-ancestors: the split people get wrong
An embedded app must be framable by the shop and the admin - and nothing else. Public pages must be framable by nothing. Those are two different policies:
# Embedded admin surface
Content-Security-Policy: frame-ancestors https://{shop}.myshopify.com https://admin.shopify.com;
# Public marketing / privacy / support pages
Content-Security-Policy: frame-ancestors 'none';
If you set 'none' on the admin surface, you get a blank iframe. If you set a wildcard everywhere, you've made your admin pages embeddable by anyone. Scope the store-specific variant when you know the shop, and fall back to https://*.myshopify.com https://admin.shopify.com only when you don't - because a framed reload that loses its query string would otherwise break.
The 401 retry header the template gives you
When your API returns 401 for an invalid or expired session token, add:
X-Shopify-Retry-Invalid-Session-Request: 1
App Bridge intercepts that response, fetches a fresh ID token, and retries the request once. This is easy to miss when you hand-roll the backend - without it, every short-lived-token expiry becomes a user-visible failure instead of an invisible refresh.
What else you now own if you skip the template
To be fair to the template, "skipping it" isn't one decision - it's adopting a list:
- OAuth install/callback and HMAC verification of the query string
- Webhook HMAC verification and subscription management
- Session storage, token exchange, and refresh rotation
- Bounce/exit-iframe handling (top-level redirects escape the iframe)
- CSP, App Bridge version pinning, and the App Store rule that install must start on a Shopify-owned surface
- Billing helpers and uninstall/reinstall lifecycle
- Per-request
shopify-api-key injection. The built index.html keeps a %SHOPIFY_API_KEY% placeholder - the build fails if a key gets baked in - and the server substitutes its own key on each admin request. The same artifact can serve whichever app installs it, and a dev key can never leak into a shared bundle.
Each is doable, and each is a way to ship a subtle bug. The template's real value isn't the code - it's not having to re-derive these decisions and not owning their security patches forever.
When I'd still use the template
If you're on Node/Remix and don't specifically need a non-Node backend, use the template. It's the right default. I went custom because the backend is Rust/Axum and I wanted one language end-to-end, and that tradeoff was worth it for this app. It is not worth it just to avoid a dependency.
The no-Node shape also means production is a single binary plus static files - no SSR server to keep warm. That was a hosting decision as much as a language preference. The admin SPA is client-rendered; the public pages are server-rendered by the same Rust binary.
The point of writing this isn't "custom is better." It's that the auth boundary is the part that actually matters, and it's worth understanding even if the template does it for you.
Further reading: Shopify's "Authenticate an embedded app without a template" doc covers the official checklist for all of the above.
I build backend-heavy Shopify apps - embedded auth, Shopify Functions, Protected Customer Data, and App Store launches. If you're stuck on any of this, happy to answer questions here; DMs are open.