Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fabiensebban/e05d82d39715973014637f8949ad9ef2 to your computer and use it in GitHub Desktop.
Save fabiensebban/e05d82d39715973014637f8949ad9ef2 to your computer and use it in GitHub Desktop.
# This code can be used to decode the session token coming from the
# Customer UI extension: https://shopify.dev/docs/api/customer-account-ui-extensions/2024-10/apis/session-token
require 'jwt'
require 'json'
# Replace with your app's client secret from the Partner Dashboard
SHOPIFY_CLIENT_SECRET = "XXX"
# Token present in the Authorization header of the request
token = "yyyy"
decoded_token = JWT.decode(token, SHOPIFY_CLIENT_SECRET, true, { algorithm: 'HS256' })
# Shopify's session token payload is in the first element of the array
payload = decoded_token[0]
# Example: Log the customer id or destination shop
puts "Verified session for shop: #{payload['dest']}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment