Shopifex.SessionToken (Shopifex v3.0.0)

Copy Markdown View Source

Verifies Shopify App Bridge session tokens (id_token) directly.

This is the embedded-app authentication primitive: a strict HS256 verify of the JWT Shopify signs with your app's API secret, checking that:

  • the signature is valid (HS256 only — no algorithm confusion),
  • the audience (aud) equals your app's API key,
  • the destination (dest) is a well-formed *.myshopify.com shop domain (Shopifex.ShopDomain.valid?/1; it matches the expected shop when one is supplied),
  • the issuer (iss) is #{dest}/admin,
  • the token is within its (very short, ~60s) validity window.

:expired is returned as a distinct error from other failures so callers can log routine expiries at :info (stale bfcache loads, clock skew) while treating signature/audience failures as genuine anomalies.

Replaces the Guardian-based session-token handling used in Shopifex v2.

Configuration

config :shopifex,
  api_key: "your_api_key",
  secret: "your_api_secret"

Summary

Functions

Verify a Shopify session token. Returns {:ok, claims} or {:error, reason}.

Functions

verify(token)

@spec verify(String.t()) :: {:ok, map()} | {:error, atom()}

Verify a Shopify session token. Returns {:ok, claims} or {:error, reason}.

Pass the shop's *.myshopify.com URL as the second argument to additionally assert the token's dest matches that shop.

verify(token, shop_url)

@spec verify(String.t(), String.t()) :: {:ok, map()} | {:error, atom()}