More Resilient Refreshes for Expiring Offline Access Tokens: What Developers Need to Know

Shopify now lets apps retry the original refresh token for up to 30 days, giving a safety net for lost token responses. Learn who’s affected, why it matters, and how to implement atomic token storage.

More Resilient Refreshes for Expiring Offline Access Tokens: What Developers Need to Know
6 sections

Shopify’s latest developer update introduces a more forgiving refresh flow for expiring offline access tokens. If your app ever loses the response from a token‑refresh request, you now have a built‑in recovery window that can keep your integration humming without forcing merchants to reopen the app. This post breaks down the change, explains who it impacts, and provides clear, actionable steps (including sample code) to ensure your app stays resilient.

What Changed

Previously, once an app used a refresh token, that token could be retried for only 60 minutes. If the app failed to capture the new access‑token/refresh‑token pair—because of a network glitch, a crashed worker, or a DB write error—the original refresh token became unusable after that window, forcing the merchant to re‑authorize the app.

The new behavior extends the retry window dramatically. After you call the refresh endpoint, Shopify will keep the *previous* refresh token valid until you start using the *replacement* token that Shopify returns. This safety net lasts for up to 30 days from the first use of the original token, but it does not extend the overall 90‑day token lifespan. Once you store and start using the new token, the old one is retired automatically.

Who Is Affected

The change only applies to apps that have opted into *expiring* offline access tokens (the default for new apps and for existing apps that have migrated). If your integration still relies on non‑expiring offline tokens, nothing changes for you. No new API version, configuration flag, or opt‑in is required—Shopify rolls this out automatically for qualifying apps.

Why This Matters for Your App

A transient failure during a refresh cycle can leave your database without the latest token pair while Shopify has already invalidated the old refresh token. That scenario typically forces a merchant to open the app again, triggering a new OAuth flow—a poor experience that can lead to missed orders or broken automation.

With the 30‑day fallback, your background worker can simply retry the same refresh token until you successfully persist the new pair. This gives you a reliable recovery path without any extra code paths, reducing support tickets and improving uptime for any scheduled jobs that depend on the offline token (e.g., order sync, inventory updates, analytics pipelines).

Actionable Steps for Developers

Even though Shopify handles the extended window for you, you should still follow best practices to make the most of it:

  • Serialize refresh operations per shop – Ensure only one refresh request runs at a time for a given store. Use a distributed lock (Redis SETNX, database row lock, etc.) to avoid race conditions that could produce multiple overlapping token pairs.
  • Persist token pairs atomically – Write the new access token *and* refresh token in a single transaction. If your DB supports multi‑row transactions, wrap the write in a transaction block; otherwise, use a single document update (e.g., MongoDB updateOne) that includes both fields.
  • Always use the newest refresh token – After a successful refresh, update the stored token immediately and use that value for the next refresh. The older token remains valid only as a fallback; once the new token is persisted, treat the old one as retired.
  • Log refresh outcomes – Record whether the refresh succeeded, failed, or was retried using the fallback token. This visibility helps you spot patterns (e.g., frequent DB timeouts) before they affect merchants.
  • Sample Code: Atomic Storage of Token Pair

    Below is a Node.js/Express example using a PostgreSQL transaction to store the refreshed tokens atomically. Adjust the database client to match your stack (MySQL, MongoDB, etc.).

    javascript

    // refreshTokens.js – called when Shopify returns a new token pair

    async function handleRefresh(shop, newAccessToken, newRefreshToken) {

    const client = await pool.connect();

    try {

    await client.query('BEGIN');

    // Update both columns in a single row – atomic operation

    const sql = `

    UPDATE shop_tokens

    SET access_token = $1,

    refresh_token = $2,

    refreshed_at = NOW()

    WHERE shop = $3

    `;

    await client.query(sql, [newAccessToken, newRefreshToken, shop]);

    await client.query('COMMIT');

    console.log(✅ Tokens refreshed for ${shop});

    } catch (err) {

    await client.query('ROLLBACK');

    console.error('❌ Failed to persist token pair', err);

    // Let the caller retry – the old refresh token is still valid for up to 30 days

    throw err;

    } finally {

    client.release();

    }

    }

    Conclusion & Next Steps

    Shopify’s extended refresh window is a silent safety net that protects your background jobs from rare but disruptive failures. No migration is required, but treating the fallback as a contingency rather than a permanent shortcut is key. By serializing refresh calls, persisting token pairs in a single transaction, and always swapping to the newest refresh token, you’ll keep your app’s offline access robust for the full 90‑day lifecycle.

    Ready to tighten up your token handling? Review your refresh logic today, add the atomic storage pattern shown above, and monitor your logs for any retry events. A more resilient token flow means fewer merchant interruptions and a smoother experience for everyone.

    Tags
    Sources

    Related Articles

    Guaranteed Flat‑Rate Shipping Goes Global with Managed Markets

    Guaranteed Flat‑Rate Shipping Goes Global with Managed Markets

    Shopify’s new Managed Markets feature adds duty‑inclusive, guaranteed flat‑rate shipping to international markets, automating rates and protecting merchants from label‑cost surprises. Learn what’s changed, who it impacts, and how to enable it.

    October 24, 20264 min
    Create Transparent‑Background Images Directly in Shopify Sidekick

    Create Transparent‑Background Images Directly in Shopify Sidekick

    Shopify Sidekick now lets merchants generate illustrations, icons, and graphics with transparent backgrounds using AI prompts—no extra design tools required. Learn how it works, who benefits, and how to get started today.

    October 24, 20264 min
    UK VAT Gets Smarter: Fulfillment Location Drives Accurate Tax on Orders Over £135

    UK VAT Gets Smarter: Fulfillment Location Drives Accurate Tax on Orders Over £135

    Shopify now calculates UK VAT based on the fulfillment location chosen by your order‑routing rules. Orders over £135 that ship from outside the UK are treated as imports, removing VAT at checkout. Learn what this means for merchants and developers and how to update your routing settings.

    October 23, 20264 min
    Schedule and Test Catalog Changes with Rollouts: A Deep Dive

    Schedule and Test Catalog Changes with Rollouts: A Deep Dive

    Shopify Rollouts now lets merchants schedule catalog availability and pricing by market, and lets developers test those changes before they go live. Learn what’s new, who it impacts, and step‑by‑step actions to start using Rollouts today.

    October 23, 20264 min