ShopifyAutoAuth
Enterprise-Grade Shopify OAuth 2.0 Client Credentials Adapter
A zero-friction, production-hardened bridge connecting legacy Shopify applications to modern Client Credentials Grant authentication.
[](https://github.com/AhmadHassan-BTed/ShopifyAutoAuth/actions)
[](https://pypi.org/project/shopify-auth-adapter/)
[](https://pypi.org/project/shopify-auth-adapter/)
[](LICENSE)
[-8a2be2?style=for-the-badge)](https://github.com/AhmadHassan-BTed)
---
## Overview
Following Shopify's mandatory authentication migration on **January 1, 2026**, static `shpat_xxx` custom app tokens were deprecated in favor of **OAuth 2.0 Client Credentials Grant** short-lived access tokens (RFC 6749 §4.4).
`shopify_auth_adapter` provides a transparent authentication proxy. Existing applications can preserve their variable assignment patterns while under the hood tokens are acquired, cached in volatile RAM, and refreshed prior to expiration without runtime interruption.
### Migration: Before vs After
```python
# BEFORE (Deprecated static token):
SHOPIFY_ACCESS_TOKEN = "shpat_xxxxxxxxxxxxxxxxxxxxxxxx"
# AFTER (Automatic OAuth 2.0 token with auto-refresh):
from shopify_auth_adapter import get_access_token
SHOPIFY_ACCESS_TOKEN = get_access_token()
```
---
## ⚡ Quick Start: 1 Line of Code
To upgrade any Python application to Shopify's modern OAuth 2.0 authentication, replace your deprecated `shpat_xxx` string with **`get_access_token()`**:
```python
from shopify_auth_adapter import get_access_token
# Automatically fetches, caches in RAM, and auto-refreshes OAuth 2.0 tokens:
SHOPIFY_ACCESS_TOKEN = get_access_token()
```
That's it! Everything else (OAuth 2.0 requests, RAM caching, automatic 24h refresh) happens automatically behind the scenes.
### Installation
```bash
pip install shopify-auth-adapter
```
### Setting Up Credentials
You can supply your Shopify Dev Dashboard credentials in **any of 3 ways**:
#### Option A: In a `.env` file (Recommended for Local Dev)
Create a `.env` file in your project root:
```env
SHOPIFY_SHOP=your-store.myshopify.com
SHOPIFY_CLIENT_ID=your_client_id
SHOPIFY_CLIENT_SECRET=your_client_secret
```
#### Option B: Environment Variables (Production / Docker / Cloud)
Set variables in your terminal or deployment environment:
```bash
export SHOPIFY_SHOP="your-store.myshopify.com"
export SHOPIFY_CLIENT_ID="your_client_id"
export SHOPIFY_CLIENT_SECRET="your_client_secret"
```
#### Option C: Pass Directly in Python Code
```python
from shopify_auth_adapter import get_access_token
token = get_access_token(
shop="your-store.myshopify.com",
client_id="your_client_id",
client_secret="your_client_secret",
)
```
---
### Testing Credentials
You can verify your Dev Dashboard credentials and store connection instantly by running the included tester script:
```bash
python examples/test_credentials.py
```
---
### Usage Examples
#### 1. Drop-In Token Helper
```python
import httpx
from shopify_auth_adapter import get_access_token
# Automatically reads credentials from .env or environment variables:
headers = {"X-Shopify-Access-Token": get_access_token()}
response = httpx.get(
"https://your-store.myshopify.com/admin/api/2026-07/shop.json",
headers=headers,
)
```
#### 2. High-Level Shopify Client
```python
from shopify_auth_adapter import ShopifyClient
# Automatically attaches tokens and retries on 401:
client = ShopifyClient()
# REST API call
blogs = client.get("/blogs.json").json()["blogs"]
# GraphQL API call
shop_info = client.graphql("""
query {
shop {
name
email
}
}
""")
```
---
## Feature Matrix
| Domain | Capability | Architectural Mechanism |
| :--- | :--- | :--- |
| **Authentication** | OAuth 2.0 Client Credentials Grant | Automatic `POST /admin/oauth/access_token` exchange for Dev Dashboard apps. |
| **Concurrency** | Thundering Herd Protection | Re-entrant `threading.RLock` double-checked locking mechanism. |
| **Resilience** | Clock-Skew Mitigation | 300-second (5-minute) proactive expiration cutoff buffer. |
| **Header Integration**| Transparent `LiveToken` Proxy | Custom `str` subclass executing JIT encoding delegation during HTTP header resolution. |
| **Client Abstraction**| High-Level `ShopifyClient` | Integrated REST & GraphQL client with automatic 401 cache-invalidation and single retry. |
| **Security** | Zero Credential Leak Guarantee | String masking on `repr`, `str`, and tracebacks (`LiveToken(