Skip to main content

shopify_auth_adapter

CI Status PyPI Version Python Versions License

Production-grade Python library providing automatic, thread-safe authentication for the Shopify Admin API via the OAuth 2.0 Client Credentials Grant.

Designed as an enterprise-ready, drop-in replacement for legacy static shpat_xxx access tokens with zero code refactoring required for existing applications.


📖 Contents


❓ Why This Library Exists

Since January 1, 2026, Shopify no longer allows creating Custom Apps with permanent static shpat_xxx tokens in store admin settings. All new applications must use the Shopify Dev Dashboard and the OAuth 2.0 Client Credentials Grant.

Tokens issued under this flow expire after 24 hours and must be refreshed programmatically. shopify_auth_adapter handles token acquisition, thread-safe in-memory caching, proactive expiration renewal, and HTTP header delegation transparently.


✨ Key Features

  • 🔐 OAuth 2.0 Client Credentials Grant: Implements RFC 6749 §4.4 for Shopify Dev Dashboard applications.
  • Double-Checked Locking: Thread-safe token refresh prevents thundering-herd calls under high concurrency.
  • ⏱️ Clock-Skew Buffer Protection: Proactively refreshes tokens 300 seconds before expiry to prevent transit boundary failures.
  • 🛡️ Zero Credential Leak Guarantee: Access tokens and client secrets are masked in logs, tracebacks, and repr outputs.
  • 🔄 Transparent LiveToken Proxy: A str subclass proxy that auto-refreshes headers without breaking static assignment patterns.
  • 🌐 High-Level ShopifyClient: Built-in REST and GraphQL API client with automated 401 retry handling.
  • 📦 PEP 561 Typed: Full inline static type annotations (py.typed).

🏛️ Architecture Overview

graph TD
    App[Application Code] -->|get_access_token| Facade[shopify_auth_adapter Facade]
    Facade -->|delegates to| Mgr[TokenManager]
    Mgr -->|reads/writes| Cache[InMemoryTokenCache]
    Mgr -->|double-checked lock| Provider[OAuth2ClientCredentialsProvider]
    Provider -->|HTTP POST| Shopify[Shopify OAuth Token Endpoint]
    
    App -->|ShopifyClient| Client[ShopifyClient]
    Client -->|auto-attaches token| Mgr

For complete details on domain separation, check docs/architecture.md and docs/system-design.md.


⚙️ Installation

Install via pip:

pip install shopify-auth-adapter

Or install from GitHub:

pip install git+https://github.com/AhmadHassan-BTed/ShopifyAutoAuth.git

🔑 Environment Configuration

Create a .env file in your root directory (see .env.example):

SHOPIFY_SHOP=my-store.myshopify.com
SHOPIFY_CLIENT_ID=your_client_id_from_dev_dashboard
SHOPIFY_CLIENT_SECRET=your_client_secret_from_dev_dashboard
SHOPIFY_API_VERSION=2026-07

🚀 Quick Start

1. Drop-in Replacement

Replace static token assignment with get_access_token():

from shopify_auth_adapter import get_access_token

# Before:
# SHOPIFY_ACCESS_TOKEN = "shpat_xxxxxxxxx"

# After (automatically refreshes before expiry):
SHOPIFY_ACCESS_TOKEN = get_access_token()

headers = {"X-Shopify-Access-Token": SHOPIFY_ACCESS_TOKEN}

2. High-Level ShopifyClient (REST & GraphQL)

Use ShopifyClient for clean API interactions:

from shopify_auth_adapter import ShopifyClient

shopify = ShopifyClient()

# REST Admin API
blogs = shopify.get("/blogs.json").json()["blogs"]

# GraphQL Admin API
data = shopify.graphql("""
    query {
        blogs(first: 5) {
            edges { node { id title } }
        }
    }
""")

🛡️ Security & Masking Invariants

  • Masked Repr: Printing LiveToken or CachedToken outputs <masked> or <redacted>.
  • In-Memory Only: Tokens exist only in RAM (InMemoryTokenCache) and are never written to disk.
  • HTTPS Strict: All requests enforce TLS certificate verification.

🛠️ Development & Testing

This project includes a standardized Makefile for developer tooling:

# Setup editable installation with dev tools
make install

# Run full test suite with coverage
make test

# Run quality checks (linter, format check, typecheck, tests)
make check

📚 Documentation

Detailed technical documentation is available in docs/:


📄 License

Distributed under the MIT License. See LICENSE for more information.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shopify_auth_adapter-1.0.0.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shopify_auth_adapter-1.0.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file shopify_auth_adapter-1.0.0.tar.gz.

File metadata

  • Download URL: shopify_auth_adapter-1.0.0.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for shopify_auth_adapter-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7bd86711f734051161e6b4ea7f3f341888f6043d6dff3eeaf63faef3e6160b2c
MD5 09a539b010e9c6aebe32132d129cbc8b
BLAKE2b-256 8c1dc242662324ff3b3b16429a79684fba42bbf4b46e9eba4a91d87d289f0a00

See more details on using hashes here.

File details

Details for the file shopify_auth_adapter-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shopify_auth_adapter-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e6bd54740d91d530256a8530a65651a5bd9ee96ed051565e2bbaf14c0fb20fb
MD5 9a815d92f8a2f8b7bc4eadd1b18f06e5
BLAKE2b-256 8c272138a48f01b84c0c1403bfd62ecc85431b1ec7be3239396b6cf3f08f1a74

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page