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.
Anchor to Use casesUse cases
- 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
subclaim 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
destclaim to confirm which shop the request is associated with, ensuring your backend responds with the correct data.
Supported targets
- customer-account.
footer. render-after - customer-account.
order-index. announcement. render - customer-account.
order-index. block. render - customer-account.
order-status. announcement. render - customer-account.
order-status. block. render - customer-account.
order-status. cart-line-item. render-after - customer-account.
order-status. cart-line-list. render-after - customer-account.
order-status. customer-information. render-after - customer-account.
order-status. fulfillment-details. render-after - customer-account.
order-status. payment-details. render-after - customer-account.
order-status. return-details. render-after - customer-account.
order-status. unfulfilled-items. render-after - customer-account.
order. action. menu-item. render - customer-account.
order. action. render - customer-account.
order. page. render - customer-account.
page. render - customer-account.
profile. addresses. render-after - customer-account.
profile. announcement. render - customer-account.
profile. block. render - customer-account.
profile. company-details. render-after - customer-account.
profile. company-location-addresses. render-after - customer-account.
profile. company-location-payment. render-after - customer-account.
profile. company-location-staff. render-after - customer-account.
profile. payment. render-after
Supported targets
- customer-account.
footer. render-after - customer-account.
order-index. announcement. render - customer-account.
order-index. block. render - customer-account.
order-status. announcement. render - customer-account.
order-status. block. render - customer-account.
order-status. cart-line-item. render-after - customer-account.
order-status. cart-line-list. render-after - customer-account.
order-status. customer-information. render-after - customer-account.
order-status. fulfillment-details. render-after - customer-account.
order-status. payment-details. render-after - customer-account.
order-status. return-details. render-after - customer-account.
order-status. unfulfilled-items. render-after - customer-account.
order. action. menu-item. render - customer-account.
order. action. render - customer-account.
order. page. render - customer-account.
page. render - customer-account.
profile. addresses. render-after - customer-account.
profile. announcement. render - customer-account.
profile. block. render - customer-account.
profile. company-details. render-after - customer-account.
profile. company-location-addresses. render-after - customer-account.
profile. company-location-payment. render-after - customer-account.
profile. company-location-staff. render-after - customer-account.
profile. payment. render-after
Anchor to PropertiesProperties
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 sessionTokensessionTokensessionTokenSessionTokenSessionTokenrequiredrequired
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.
SessionToken
Authenticates requests between your extension and your app backend. Use session tokens to verify the identity of the buyer and the shop context when making server-side API calls. The token is a signed JWT that contains claims such as the customer ID, shop domain, and expiration. The `sub` claim in the decoded token is present only when the buyer is logged in and the app has permission to read customer accounts. Absent for anonymous buyers.
- get
Requests a session token that hasn't expired. You should call this method every time you need to make a request to your backend in order to get a valid token. This method returns cached tokens when possible, so you don't need to worry about storing these tokens yourself.
() => Promise<string>
Anchor to Best practicesBest practices
- 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.
Anchor to LimitationsLimitations
- Session tokens expire after 5 minutes. Your backend must handle expired tokens and your extension should request a new token for each request.
- The
subclaim is only present when the customer is signed in and your app has theread_customersscope. 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.