Session Token API
The Session Token API provides a method to request a signed JSON Web Token (JWT) from Shopify. Use this API to authenticate requests from your checkout extension to your application server. The token's claims are signed with your app secret, so your server can verify they came from Shopify unaltered.
Using fetch() from a checkout extension requires the network_access capability to be enabled in your extension configuration.
The sub claim in the decoded token is present only when the buyer is logged in and your app has permission to read customer accounts. For anonymous buyers, the claim is absent.
Anchor to Use casesUse cases
- Authenticate server requests: Pass the session token as a bearer token in
fetch()calls to your backend so your server can verify the request came from a Shopify checkout. - Identify the customer: Extract the customer's GID from the optional
subclaim when the buyer is logged in and your app has permission to read customer accounts. - Validate checkout context: Use the token claims to confirm the shop, extension, and checkout context on your server before processing a request.
Supported targets
- purchase.
address-autocomplete. format-suggestion - purchase.
address-autocomplete. suggest - purchase.
checkout. actions. render-before - purchase.
checkout. block. render - purchase.
checkout. cart-line-item. render-after - purchase.
checkout. cart-line-list. render-after - purchase.
checkout. chat. render - purchase.
checkout. contact. render-after - purchase.
checkout. delivery-address. render-after - purchase.
checkout. delivery-address. render-before - purchase.
checkout. footer. render-after - purchase.
checkout. header. render-after - purchase.
checkout. payment-method-list. render-after - purchase.
checkout. payment-method-list. render-before - purchase.
checkout. pickup-location-list. render-after - purchase.
checkout. pickup-location-list. render-before - purchase.
checkout. pickup-location-option-item. render-after - purchase.
checkout. pickup-point-list. render-after - purchase.
checkout. pickup-point-list. render-before - purchase.
checkout. reductions. render-after - purchase.
checkout. reductions. render-before - purchase.
checkout. shipping-option-item. details. render - purchase.
checkout. shipping-option-item. render-after - purchase.
checkout. shipping-option-list. render-after - purchase.
checkout. shipping-option-list. render-before - purchase.
thank-you. announcement. render - purchase.
thank-you. block. render - purchase.
thank-you. cart-line-item. render-after - purchase.
thank-you. cart-line-list. render-after - purchase.
thank-you. chat. render - purchase.
thank-you. customer-information. render-after - purchase.
thank-you. footer. render-after - purchase.
thank-you. header. render-after
Supported targets
- purchase.
address-autocomplete. format-suggestion - purchase.
address-autocomplete. suggest - purchase.
checkout. actions. render-before - purchase.
checkout. block. render - purchase.
checkout. cart-line-item. render-after - purchase.
checkout. cart-line-list. render-after - purchase.
checkout. chat. render - purchase.
checkout. contact. render-after - purchase.
checkout. delivery-address. render-after - purchase.
checkout. delivery-address. render-before - purchase.
checkout. footer. render-after - purchase.
checkout. header. render-after - purchase.
checkout. payment-method-list. render-after - purchase.
checkout. payment-method-list. render-before - purchase.
checkout. pickup-location-list. render-after - purchase.
checkout. pickup-location-list. render-before - purchase.
checkout. pickup-location-option-item. render-after - purchase.
checkout. pickup-point-list. render-after - purchase.
checkout. pickup-point-list. render-before - purchase.
checkout. reductions. render-after - purchase.
checkout. reductions. render-before - purchase.
checkout. shipping-option-item. details. render - purchase.
checkout. shipping-option-item. render-after - purchase.
checkout. shipping-option-list. render-after - purchase.
checkout. shipping-option-list. render-before - purchase.
thank-you. announcement. render - purchase.
thank-you. block. render - purchase.
thank-you. cart-line-item. render-after - purchase.
thank-you. cart-line-list. render-after - purchase.
thank-you. chat. render - purchase.
thank-you. customer-information. render-after - purchase.
thank-you. footer. render-after - purchase.
thank-you. header. render-after
Anchor to Properties and methodsProperties and methods
The shopify global object provides session token capabilities for the current checkout. Access the following properties and methods on shopify to request a signed JSON Web Token (JWT) for server authentication. Available to purchase extension targets.
- Anchor to sessionTokensessionTokensessionTokenSessionTokenSessionTokenrequiredrequired
The session token providing a set of claims as a signed JSON Web Token (JWT).
The token has a TTL of five minutes.
If the previous token expires, this value reflects a new session token with a new signature and expiry.
Learn more about session tokens.
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 a fresh token before each server call: Session tokens have a TTL of five minutes. Always call
sessionToken.get()immediately before making afetch()request rather than storing a previously retrieved token string. CallingsessionToken.get()before eachfetch()doesn't significantly impact performance, because Shopify caches the token internally and returns it if it's still valid. - Don't trust the full HTTP request: Validate only the signed token claims. Your server can trust the claims inside the session token, but it can't use the token to trust the entire HTTP request body or headers.