Skip to main content

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.

  • 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 sub claim 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.
Support
Targets (33)

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 sessionToken
sessionToken
required

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.


  • Request a fresh token before each server call: Session tokens have a TTL of five minutes. Always call sessionToken.get() immediately before making a fetch() request rather than storing a previously retrieved token string. Calling sessionToken.get() before each fetch() 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.

Was this page helpful?