api.integrations.shopify.auth

Shopify Admin API access tokens, exchanged from the app’s client credentials.

A Dev Dashboard app has no permanent token: SHOPIFY_CLIENT_ID and SHOPIFY_CLIENT_SECRET are exchanged for a token that Shopify expires after about 24 hours. The token is kept in Redis, so the API and every worker share one exchange, plus in memory; it is renewed before it expires. After a 401 (token revoked early), callers ask again with the rejected token, which forces a new exchange unless another process already has a newer one. Without Redis, the in-memory copy alone is used.

Attributes

Exceptions

ShopifyAuthError

No Admin API access token could be obtained.

Classes

ShopifyTokenProvider

Returns a valid token for one store (see the module docstring).

Functions

exchange_client_credentials(domain, client_id, ...) → tuple[str, int]

(access_token, expires_in seconds) straight from Shopify.

get_shopify_access_token([rejected]) → str

A token for the configured store (SHOPIFY_SHOP_DOMAIN).

Module Contents

api.integrations.shopify.auth.logger
api.integrations.shopify.auth.REQUEST_TIMEOUT_SECONDS = 30
api.integrations.shopify.auth.REFRESH_MARGIN_SECONDS = 600
api.integrations.shopify.auth.EXCHANGE_LOCK_TTL_SECONDS = 30
api.integrations.shopify.auth.EXCHANGE_WAIT_SECONDS = 10.0
api.integrations.shopify.auth.EXCHANGE_WAIT_POLL_SECONDS = 0.25
api.integrations.shopify.auth.TokenProvider
exception api.integrations.shopify.auth.ShopifyAuthError

Bases: RuntimeError

No Admin API access token could be obtained.

api.integrations.shopify.auth.exchange_client_credentials(domain: str, client_id: str, client_secret: str) → tuple[str, int]

(access_token, expires_in seconds) straight from Shopify.

class api.integrations.shopify.auth.ShopifyTokenProvider(domain: str, client_id: str, client_secret: str, redis_factory: collections.abc.Callable[[], redis.Redis[str]] | None = None)

Returns a valid token for one store (see the module docstring).

domain
client_id
client_secret
api.integrations.shopify.auth.get_shopify_access_token(rejected: str | None = None) → str

A token for the configured store (SHOPIFY_SHOP_DOMAIN).