Skip to content

devwhodevs/shopify-app-token-obtainer

Repository files navigation

shopify-app-token-obtainer

One-command tool to obtain a Shopify offline access token via the OAuth authorization code grant. Spins up a local server, tunnels it through Cloudflare, deploys the redirect URL to Shopify via CLI, and walks you through the OAuth flow in the browser.

Prerequisites

  • Node.js 18+
  • pnpm
  • cloudflared (brew install cloudflared)
  • Shopify CLI (npm install -g @shopify/cli), logged in via shopify auth login

Setup

pnpm install
cp .env.example .env
cp shopify.app.toml.example shopify.app.toml

Fill in .env:

CLIENT_ID=your_shopify_app_client_id
CLIENT_SECRET=your_shopify_app_client_secret
SHOP=your-store.myshopify.com
SCOPES=read_products,write_orders

Link your Shopify app (first time only — this populates shopify.app.toml with your app config):

shopify app config link --client-id <your_client_id>

Usage

pnpm start

This single command:

  1. Starts an HTTP server on port 3000
  2. Opens a Cloudflare tunnel (free, no account needed)
  3. Updates shopify.app.toml with the tunnel URL
  4. Runs shopify app deploy to push the redirect URL to the Shopify dashboard
  5. Prints a URL to open in your browser

Click the link, approve scopes, and the offline access token (shpat_...) is displayed on screen.

How it works

Implements the Shopify authorization code grant:

  1. GET / — landing page with "Authorize App" button
  2. GET /callback (no code) — redirects to Shopify's grant screen
  3. GET /callback?code=... — exchanges the code for an offline token via POST /admin/oauth/access_token

Offline tokens are requested by omitting grant_options[]. The token does not expire and persists until the app is uninstalled.

Configuration

All config is in .env. Scopes are passed as a comma-separated string. The shopify.app.toml is auto-updated on each run with the new tunnel URL — you don't need to touch it.

Variable Description
CLIENT_ID App API key from Shopify Partners
CLIENT_SECRET App API secret (never committed)
SHOP your-store.myshopify.com
SCOPES Comma-separated OAuth scopes
PORT Server port (default: 3000)

License

MIT

About

One-command Shopify offline access token via OAuth + Cloudflare tunnel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors