Skip to main content

Session Token API

The Session Token API lets you authenticate requests from your extension to your app's backend using a signed JSON Web Token (JWT). Use this API to get a token that your backend can verify using your app's shared secret, confirming the request came from a legitimate Shopify extension.

  • Authenticate backend requests: Pass a session token as a Bearer token in API calls to your app's backend so you can verify the request came from your extension.
  • Identify the customer: Read the optional sub claim in the token to get the customer's GID when they're signed in and your app has access to protected customer data.
  • Verify the shop: Use the dest claim to confirm which shop the request is associated with, ensuring your backend responds with the correct data.
Support
Targets (24)

The shopify global object provides session token functionality for customer account extensions. Access the following properties on shopify to retrieve signed tokens for authenticating requests to your app's backend.

Anchor to sessionToken
sessionToken
required

Authenticates requests between your extension and your app backend. Call get() to retrieve a signed JWT containing the customer ID, shop domain, and expiration time, then verify it server-side. For more information, refer to the Session Token API.


  • Request tokens close to usage: Call shopify.sessionToken.get() immediately before making a request rather than storing the token for later, since tokens expire after 5 minutes.
  • Verify tokens server-side: Always validate the token signature, expiration (exp), and audience (aud) on your backend using your app's shared secret.
  • Handle token errors gracefully: Wrap token retrieval and fetch calls in try-catch blocks so your extension can display a meaningful message if authentication fails.

  • Session tokens expire after 5 minutes. Your backend must handle expired tokens and your extension should request a new token for each request.
  • The sub claim is only present when the customer is signed in and your app has the read_customers scope. Don't rely on it being available in all contexts.
  • Session tokens are signed JWTs intended for your backend only. Don't expose sensitive claims to the customer or use them for client-side authorization decisions.

Was this page helpful?