CodeSapient
← All articles

Shopify Expiring Offline Access Tokens: How to Migrate Your App

From 1 December 2026, new Shopify custom apps must use expiring offline access tokens. Who is affected, the 2027 public app deadlines, migration paths, and a tested refresh routine.

By CodeSapient Labs ·
Split-flap departure board titled Offline access tokens with three rows: access token, 1 hour, refresh; refresh token, 90 days, rotate; non-expiring, April 2027, rejected, with green, green and red status lamps

Starting today, 1 December 2026, every new Shopify custom app and every new app a merchant creates must use Shopify expiring offline access tokens for the GraphQL Admin API and REST Admin API. Public apps have had the same rule for new apps since 1 April 2026, and public apps that still use the old non-expiring tokens get delisted on 1 January 2027. From 1 April 2027 their Admin API requests are rejected.

If your integration stores one offline token per store and uses it forever, that model is going away. This guide covers what changed, how to tell whether your app is affected, how to migrate each type of app, and how to write a refresh routine that holds up when retries and several workers want a token at once. We tested the code against a local mock of Shopify's token endpoint and say exactly what that does and doesn't prove.

What changed on 1 December 2026

The Shopify changelog entry is short. For apps created on or after 1 December 2026, any new offline token obtained through the authorization code grant or token exchange must be an expiring one. You ask for it by adding expiring=1 to the token request, then you store and use the refresh token that comes back.

Who it applies to, in plain terms:

  • New custom apps (built by a partner for one store or organization) created on or after 1 December 2026: expiring tokens from day one.
  • New merchant-created apps created on or after 1 December 2026: same rule.
  • Custom and merchant-created apps created before 1 December 2026: can keep their existing offline tokens. Shopify has not announced a cutoff for them.
  • Public apps: new ones have needed expiring tokens since 1 April 2026. Existing public apps that still use non-expiring tokens are delisted and blocked from new installs on 1 January 2027, merchants see a warning in the admin from 15 January 2027, and from 1 April 2027 Shopify answers their Admin API requests with 403 Forbidden.
  • Apps using the client credentials grant or application-only access tokens: already compliant, because those tokens expire anyway.
Split-flap departure board titled Expiring token deadlines listing six dates: 1 April 2026 new public apps must use expiring tokens, 20 November 2026 public apps need an IP allowlist, 1 December 2026 new custom apps must use expiring tokens, 1 January 2027 public apps with non-expiring tokens delisted, 15 January 2027 merchants see a warning, 1 April 2027 non-expiring tokens get 403
The dates that matter, taken from Shopify's changelog and migration guide. The 15 January and 1 April 2027 steps apply to public apps.

This arrives with other security changes. Public apps calling the Admin API needed an IP allowlist by 20 November 2026, and custom apps installed outside your own organization need one for new installs now and for existing installs from 1 January 2027. The two controls work together: an expiring token limits how long a leaked token is useful, and an allowlist limits where it can be used from. If your app runs bulk operations, our guide to Shopify bulk operations covers the job side of those apps.

Is your app affected?

Work through these questions in order:

  1. Was the app created on or after 1 December 2026? Then it must request expiring offline tokens. There is no transition period.
  2. Is it a public app? Then the 2027 dates apply to you even if the app is years old.
  3. Is it an older custom or merchant-created app? Nothing breaks today, but plan the move: the security case is the same.
  4. Do you use a Shopify app template? Check that you are on a recent version and that the expiring token flag is on.

You can't tell an expiring token from a non-expiring one by looking at it. Shopify's access token documentation says offline and online tokens are opaque strings that both begin with shpat_. The reliable check is in the Dev Dashboard: open your app's Logs, filter Type to GraphQL request and Token type to Offline, non-expiring. Repeat with REST request if you still call REST endpoints. Any rows mean some code path is still sending an old token.

How expiring offline tokens behave

The new model has two credentials per store instead of one:

  • Access token: valid for one hour today (expires_in is 3600). Shopify asks you to read expires_in from the response rather than hard-coding the lifetime.
  • Refresh token: valid for 90 days when issued (refresh_token_expires_in is 7776000). Every refresh returns a new access token and a new refresh token, and you must use the new refresh token next time.

The rotation rules are forgiving, which matters when a network call fails halfway. According to Shopify's token refresh documentation, the refresh token you presented stays usable until one of these happens first: your app uses the newer refresh token, your app gets a new token through token exchange or the authorization code grant, 30 days pass since you first used it, or its original 90-day expiry arrives. So if a refresh response is lost, retrying with the token you still hold works.

Three other rules shape the design:

  • Shopify keeps one current expiring offline token per app and store. Retired access tokens keep working until their own expiry, so in-flight requests finish.
  • Don't acquire a new token and refresh the old one for the same store at the same time. Each retires the other's result.
  • When a refresh token can no longer be used, Shopify returns 401 with {"error": "invalid_request"} for every terminal case (expired, already replaced, revoked, app uninstalled). Treat it as final and re-authenticate. Network errors, timeouts, 5xx and 429 are safe to retry with the same refresh token.

Migration paths by app type

Shopify's migration guide describes three options. Option 1 changes how you get new tokens. Option 2 converts the tokens you already store. Option 3 replaces stored tokens with application-only access tokens. Most existing apps need both 1 and 2, in that order.

Apps built from a Shopify app template

If your app uses @shopify/shopify-app-react-router or @shopify/shopify-app-remix, the change is a configuration flag, followed by a deploy. This snippet is from Shopify's guide; we did not run a template app for this article.

// shopify.server.ts
const shopify = shopifyApp({
  // ...
  future: {
    expiringOfflineAccessTokens: true,
  },
});

The template then requests expiring tokens on new token exchanges and refreshes them for you.

Apps that call token exchange or OAuth directly

Add expiring=1 to the request you already make. For the authorization code grant it looks like this:

curl -X POST https://{shop}.myshopify.com/admin/oauth/access_token \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'client_id={client_id}' \
  -d 'client_secret={client_secret}' \
  -d 'code={authorization_code}' \
  -d 'expiring=1'

For token exchange, add the same parameter next to subject_token, subject_token_type and requested_token_type. Store access_token, refresh_token, expires_in and refresh_token_expires_in on the server. Never send them to the browser.

Converting the tokens you already store

Option 1 only moves a store when a merchant next opens your app. Background-only apps, such as webhook consumers, ERP sync jobs and Flow actions, may never see that visit. For those, Shopify lets you exchange a stored non-expiring token for an expiring pair without any user session:

curl -X POST https://{shop}.myshopify.com/admin/oauth/access_token \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
  -d 'client_id={client_id}' \
  -d 'client_secret={client_secret}' \
  -d 'subject_token={non_expiring_offline_token}' \
  -d 'subject_token_type=urn:shopify:params:oauth:token-type:offline-access-token' \
  -d 'requested_token_type=urn:shopify:params:oauth:token-type:offline-access-token' \
  -d 'expiring=1'

This call permanently invalidates the old token for Admin API use, so the response is the only copy of your new credentials. Shopify covers the lost-response case: repeating the same request with the original token within seven days returns the same pair, as long as you haven't refreshed it yet. Here is the batch script we used, written so that re-running it is safe:

import time
import requests
from shopify_tokens import CLIENT_ID, CLIENT_SECRET, shop_url, save_pair

OFFLINE = "urn:shopify:params:oauth:token-type:offline-access-token"

def migrate_shop(db, shop, legacy_token):
    form = {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET,
            "grant_type": "urn:ietf:params:oauth:grant-type:token-exchange",
            "subject_token": legacy_token,
            "subject_token_type": OFFLINE,
            "requested_token_type": OFFLINE,
            "expiring": "1"}
    for attempt in range(5):
        try:
            r = requests.post(f"{shop_url(shop)}/admin/oauth/access_token",
                              data=form, timeout=15)
        except requests.RequestException:
            time.sleep(2 ** attempt)   # same request within 7 days returns the same pair
            continue
        if r.status_code == 200:
            save_pair(db, shop, r.json(), commit=False)   # one transaction:
            db.execute("DELETE FROM legacy_tokens WHERE shop = ?", (shop,))
            db.commit()                                   # new pair in, old token out
            return "migrated"
        if r.status_code == 400 and r.json().get("error") == "invalid_subject_token":
            return "needs_reauth"      # get a new token via token exchange or OAuth
        if r.status_code == 429 or r.status_code >= 500:
            time.sleep(2 ** attempt)
            continue
        r.raise_for_status()
    return "retry_later"

It reads from a legacy_tokens table and uses save_pair from the refresh module below. The new pair and the deletion of the old row commit together, which matters: in our test, running the exchange again for a store whose new pair had already been refreshed returned invalid_subject_token, which the script reports as needing re-authentication. Driving the batch from the rows that remain, rather than from a list of every shop, keeps a finished store from being processed twice.

Application-only access tokens

The third option avoids storing per-store refresh tokens. Your server signs a client assertion with a private key and uses the client credentials grant to get a short-lived token for any store that installed the app. Shopify's application-only access token guide covers the key pair and request. It suits apps with many installs and mostly background work, but it is a bigger change than options 1 and 2, and this option doesn't invalidate the old stored tokens, so you still need the Dev Dashboard log check afterwards.

A refresh routine that survives production

Templates handle refresh for you. Without a template you write it yourself, and the easy version has a race: a worker pool handling a burst of webhooks just after expiry sees the expired token in every worker, and every worker refreshes.

The module below handles that. It refreshes five minutes before expiry, lets only one worker per store refresh through an atomic lease in the database, saves both new tokens before using either, retries transient failures with the same refresh token, and flags the store for re-authentication on a terminal 401 instead of looping. It uses SQLite so it runs anywhere; the same SQL works in PostgreSQL with %s placeholders, though we only ran it on SQLite.

import os, random, sqlite3, time
import requests

CLIENT_ID = os.environ["SHOPIFY_CLIENT_ID"]
CLIENT_SECRET = os.environ["SHOPIFY_CLIENT_SECRET"]
REFRESH_EARLY = 300      # refresh when less than 5 minutes are left
LEASE_SECONDS = 60       # longer than the whole retry loop below

def shop_url(shop):
    return f"https://{shop}"

class ReauthRequired(Exception):
    """Refresh token is dead: the merchant must open the app again."""

SCHEMA = """
CREATE TABLE IF NOT EXISTS shop_tokens (
  shop               TEXT PRIMARY KEY,
  access_token       TEXT NOT NULL,
  refresh_token      TEXT NOT NULL,
  access_expires_at  REAL NOT NULL,
  refresh_expires_at REAL NOT NULL,
  needs_reauth       INTEGER NOT NULL DEFAULT 0,
  lease_until        REAL NOT NULL DEFAULT 0
)"""

def save_pair(db, shop, data, commit=True):
    now = time.time()
    db.execute("""
      INSERT INTO shop_tokens (shop, access_token, refresh_token,
                               access_expires_at, refresh_expires_at)
      VALUES (?, ?, ?, ?, ?)
      ON CONFLICT (shop) DO UPDATE SET
        access_token = excluded.access_token,
        refresh_token = excluded.refresh_token,
        access_expires_at = excluded.access_expires_at,
        refresh_expires_at = excluded.refresh_expires_at,
        needs_reauth = 0, lease_until = 0""",
      (shop, data["access_token"], data["refresh_token"],
       now + data["expires_in"], now + data["refresh_token_expires_in"]))
    if commit:
        db.commit()

def get_access_token(db, shop):
    while True:
        row = db.execute("""SELECT access_token, access_expires_at, needs_reauth
                            FROM shop_tokens WHERE shop = ?""", (shop,)).fetchone()
        if row is None or row[2]:
            raise ReauthRequired(shop)
        token, expires_at, _ = row
        now = time.time()
        if expires_at - now > REFRESH_EARLY:
            return token
        # Only one worker per shop may refresh. Take a short lease atomically.
        taken = db.execute("""UPDATE shop_tokens SET lease_until = ?
                              WHERE shop = ? AND lease_until < ?""",
                           (now + LEASE_SECONDS, shop, now)).rowcount
        db.commit()
        if taken:
            return _refresh(db, shop)
        if expires_at - now > 10:
            return token          # someone else is refreshing; current token still works
        time.sleep(0.25)          # nearly expired: wait for the other worker, then re-read

def _refresh(db, shop):
    row = db.execute("SELECT access_token, access_expires_at, refresh_token "
                     "FROM shop_tokens WHERE shop = ?", (shop,)).fetchone()
    if row[1] - time.time() > REFRESH_EARLY:      # refreshed while we waited
        _release(db, shop)
        return row[0]
    form = {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET,
            "grant_type": "refresh_token", "refresh_token": row[2]}
    for attempt in range(5):
        try:
            r = requests.post(f"{shop_url(shop)}/admin/oauth/access_token",
                              data=form, timeout=10)
        except requests.RequestException:
            r = None                               # lost response: retry with the SAME refresh token
        if r is not None and r.status_code == 200:
            data = r.json()
            save_pair(db, shop, data)              # persist both tokens before using either
            return data["access_token"]
        if r is not None and r.status_code == 401:
            db.execute("UPDATE shop_tokens SET needs_reauth = 1, lease_until = 0 "
                       "WHERE shop = ?", (shop,))
            db.commit()
            raise ReauthRequired(shop)             # terminal: do not retry
        if r is not None and r.status_code != 429 and r.status_code < 500:
            _release(db, shop)
            r.raise_for_status()                   # bad request or bad credentials: a bug, not a blip
        time.sleep(min(2 ** attempt, 10) + random.random())
    _release(db, shop)
    raise RuntimeError(f"token refresh for {shop} kept failing; will retry later")

def _release(db, shop):
    db.execute("UPDATE shop_tokens SET lease_until = 0 WHERE shop = ?", (shop,))
    db.commit()

Choices worth noting:

  • The lease is a conditional UPDATE, not a lock held during the HTTP call. The worker that changes the row refreshes; the rest keep using the still-valid token or wait and re-read.
  • Re-read after taking the lease. Another worker may have finished a refresh between your first read and your lease.
  • Retries use the refresh token from the database, never one from a response you didn't fully receive.
  • A ReauthRequired store is skipped quickly, so a dead store doesn't turn into a retry storm against Shopify. Surface it in your admin or alerting so someone can ask the merchant to open the app.

During migration you also need to recognise Shopify's rejection of an old token without confusing it with a missing scope, which also returns 403. Shopify's guide says to match the phrase in the error rather than the status alone:

def is_legacy_token_rejection(resp):
    return resp.status_code == 403 and "Non-expiring access tokens are no longer accepted" in resp.text

What we tested, and what we didn't

We don't have a store we can safely break, so we wrote a small local server that follows the documented rules: one-hour access tokens (shortened to four seconds for the test), rotating refresh tokens with the grace rules above, terminal 401 invalid_request, the legacy-token exchange with seven-day recovery, and fault injection for dropped responses and 503s. The code above ran against it unchanged except for the base URL and a shorter refresh window, using Python 3.13.5, requests 2.34.2 and SQLite 3.46.1. All 19 checks passed.

Split-flap board titled Lab: mock token endpoint showing five scenarios with token request counts: eight workers with a lease made 1 request and got one token pair, eight workers without a lease made 8 requests and got eight pairs, a lost response retried made 2 requests and recovered, two 503 errors then a retry made 3 requests and recovered, a revoked refresh token made 1 request and set a reauth flag
Results from our local mock of the token endpoint. It follows Shopify's documented rules but is not Shopify.
  • Eight separate processes asking for a token at the same moment produced exactly one refresh call, and all eight then made successful API calls. Without the lease, the same eight processes made eight refresh calls and created eight token pairs.
  • When the refresh response was dropped after the server issued tokens, the retry with the same refresh token succeeded, and the next scheduled refresh also worked.
  • A revoked refresh token raised ReauthRequired after one request, and the next call returned immediately without contacting the server.
  • The migration script converted three stores, including one whose first response was dropped, and the old token we checked was refused afterwards.

What this does not prove: we did not call Shopify's real endpoints, so exact error bodies, timing and edge cases on Shopify's side are as documented, not observed. We didn't test the template flag, PostgreSQL, or application-only tokens.

Where this matters for a business

  • Agencies that build custom apps for clients. Any custom app created from today needs refresh logic before launch (our overview of custom Shopify app development shows where this fits), plus a handover note on what happens when a store's refresh token lapses.
  • ERP, WMS and accounting integrations. They run on schedules with nobody watching, so a silent refresh failure can stop a stock sync for a weekend.
  • Webhook-driven apps. Webhook handlers often call back into the Admin API. Pair the refresh routine with the idempotency and retry patterns in our guide to Shopify webhooks, HMAC, retries and idempotency.
  • Apps that rarely run. A store your app touches once a quarter still needs a refresh at least once every 90 days, or the merchant has to reopen the app.

Common mistakes

  • Saving the access token but not the new refresh token. The next refresh then uses a token that is about to be retired.
  • Refreshing from many workers at once. Use a lease, a row lock or a single scheduler per store.
  • Retrying a 401 refresh response. It is terminal by design. Flag the store and stop.
  • Treating every 403 as a token problem. Missing scopes also return 403; check the message.
  • Running the bulk migration without option 1 first. New installs keep creating non-expiring tokens and the Dev Dashboard log never goes quiet.

Recommendations

  1. List every app you maintain with its type and creation date, and check the Dev Dashboard logs for non-expiring token traffic.
  2. Ship option 1 first: expiring=1 on every offline token request, or the template flag.
  3. Add a refresh routine with single-flight protection and a clear re-authentication path before converting existing stores.
  4. Run the bulk conversion in small batches, store results in one transaction, and keep the legacy token until the new pair is saved.
  5. Alert on stores flagged for re-authentication and on refresh tokens approaching 90 days.
  6. Confirm your IP allowlist covers every server and job runner that calls the Admin API.

FAQ

Do existing custom apps have to switch today?

No. Custom and merchant-created apps created before 1 December 2026 can keep their existing offline tokens. The requirement applies to apps created on or after that date. Public apps follow the separate 2027 timeline.

How long does a Shopify expiring offline access token last?

The access token lasts one hour and the refresh token 90 days when issued. Shopify recommends reading expires_in and refresh_token_expires_in from each response instead of assuming those values.

What happens if a refresh response is lost?

Retry with the refresh token you still hold. Shopify keeps it usable until you use the newer one, with a cap of 30 days after its first use and never beyond its original expiry.

What should my app do when a refresh returns 401?

Stop retrying for that store and re-authenticate it: run token exchange the next time the merchant opens your app, or use application-only access if you have it set up.

Will my Shopify app template handle this automatically?

Recent versions of Shopify's React Router and Remix templates request and refresh expiring tokens when the expiringOfflineAccessTokens flag is enabled. Check your package version and configuration rather than assuming.

Conclusion

For apps created from today, expiring offline tokens are simply how Shopify authentication works, and public apps have until the new year to catch up. The protocol change is often a single expiring=1. The real work is around it: saving rotated tokens safely, stopping parallel refreshes, recovering from lost responses, and noticing stores that need the merchant to come back.

If you maintain a Shopify app or integration and would like help with the migration, CodeSapient builds and supports custom Shopify apps and backend integrations. You can tell us about your app and we'll suggest a plan that fits it.

← Back to Blog