Authentication overview

Shopify API authentication is the process by which applications verify their identity and gain authorized access to a Shopify store's data. This mechanism ensures that only legitimate applications with appropriate permissions can interact with the Shopify platform, protecting sensitive merchant and customer information. Shopify offers distinct authentication methods tailored for its various APIs, primarily the Admin API and the Storefront API, reflecting their different use cases and security requirements. The Admin API, used for backend operations like managing products, orders, and customers, typically employs OAuth 2.0. The Storefront API, designed for customer-facing experiences, often uses public API keys or customer access tokens for read-only access to storefront data.

Understanding the correct authentication flow and credential management is fundamental for developers building Shopify applications, custom storefronts, or integrations. Shopify's authentication infrastructure is designed to be secure and compliant with industry standards, including PCI DSS Level 1 compliance, which is essential for handling payment-related data. Developers must adhere to Shopify's guidelines for requesting and storing credentials to maintain the security and integrity of their applications and the merchant stores they interact with. The choice of authentication method depends on whether the application is public (available on the Shopify App Store), private (custom-built for a single store), or a headless storefront.

Supported authentication methods

Shopify APIs support several authentication methods, each suited for different integration scenarios:

OAuth 2.0 (Admin API)

OAuth 2.0 is the recommended authentication method for most Shopify Admin API integrations, especially for public applications listed on the Shopify App Store. It allows applications to obtain limited access to a user's data without exposing their credentials. The primary OAuth 2.0 flow used by Shopify is the Authorization Code Grant flow. This involves redirecting the merchant to Shopify to grant permissions (scopes) to the application. Upon successful authorization, Shopify redirects the merchant back to the application with an authorization code, which the application then exchanges for an access token. This access token is used to make authenticated requests to the Admin API on behalf of the merchant.

  • Scopes: Permissions in Shopify's OAuth are managed through scopes (e.g., read_products, write_orders). Applications must request specific scopes required for their functionality, and merchants must approve these permissions during the installation process.
  • Access Tokens: These are long-lived tokens that grant an application permission to access a merchant's store data. They should be securely stored and managed. Shopify also supports offline access tokens, which persist even when the merchant is not actively using the application.

API Key Authentication (Private Apps / Storefront API)

For private applications built for a single Shopify store, or for accessing the Storefront API, API key authentication is often used. This method provides direct access to specific API endpoints without the OAuth flow.

  • Admin API (Private Apps): Private apps generate an API key and password directly from the Shopify admin panel. The API key serves as the username and the password as the authentication token. This method is suitable for custom integrations where the application is managed directly by the merchant. Requests are authenticated by including the API key and password in the HTTP headers.
  • Storefront API (Public API Keys): The Storefront API uses a public API key to access publicly available data, such as product listings, collections, and blog posts. This key is typically embedded directly into client-side code (e.g., in a headless storefront) and does not require a secret component, as it only grants read access to non-sensitive data.

Customer Access Tokens (Storefront API)

When building custom storefronts that require authenticated customer actions (e.g., managing customer accounts, viewing order history, or checking out), the Storefront API uses customer access tokens. These tokens are issued after a customer logs in and are used to perform actions on behalf of that specific customer.

Here's a summary of authentication methods:

Method When to Use Security Level
OAuth 2.0 (Authorization Code Grant) Public Apps, Integrations requiring merchant consent, Admin API access High (token-based, scope-restricted, refreshable)
Private App API Key/Password Custom integrations for a single store, Admin API access Medium (direct credential access, requires secure storage)
Storefront API Public API Key Headless storefronts, public data access (products, collections) Low (read-only, public client-side use)
Storefront API Customer Access Tokens Authenticated customer actions in headless storefronts Medium (customer-specific, short-lived tokens, scope-restricted)

Getting your credentials

The process for obtaining credentials varies based on the type of application you are building:

For Public Apps (Shopify App Store)

  1. Create a Partner Account: Register for a Shopify Partner account on the Shopify Partner Dashboard. This is the central hub for managing all your apps.
  2. Create a New App: From the Partner Dashboard, navigate to 'Apps' and click 'Create app'. Select 'Public app'.
  3. Configure App Settings: Provide basic information about your app, including its name and callback URLs. Shopify will automatically generate a Client ID (API Key) and a Client Secret (API Secret Key) for your application.
  4. Define Scopes: Specify the necessary API access scopes that your app requires to function. These scopes will be presented to the merchant during the OAuth installation flow.
  5. Install on a Development Store: Use a development store to test your app's installation and authentication flow.

For Private Apps (Single Store Integrations)

  1. Access Shopify Admin: Log into the Shopify admin panel of the store you want to integrate with.
  2. Navigate to Apps: Go to 'Apps' > 'Apps and sales channels settings' > 'Develop apps'.
  3. Create a Private App: Click 'Create an app' and give it a name.
  4. Configure API Scopes: Grant the necessary Admin API permissions (scopes) for the private app.
  5. Install App: Click 'Install app' to generate the API Key and Admin API access token (password). These credentials are shown once and should be securely copied and stored immediately.

For Storefront API (Headless Commerce)

  1. Access Shopify Admin: Log into the Shopify admin panel.
  2. Navigate to Apps: Go to 'Apps' > 'Apps and sales channels settings' > 'Develop apps'.
  3. Create a Storefront API custom app: Follow the steps to create a custom app and ensure you select the option to generate a Storefront API access token.
  4. Copy Public Access Token: The generated Storefront API public access token will be displayed. This token is used directly in your frontend application for read-only access. For customer-specific actions, you'll manage customer access tokens programmatically after customer login.

Authenticated request example

Below is an example of an authenticated request to the Shopify Admin API using a private app's API key and password. This example fetches a list of products using a basic HTTP request, demonstrating how to include the credentials in the header.

Method: GET

Endpoint: https://{shop}.myshopify.com/admin/api/2024-04/products.json

Headers:

  • X-Shopify-Access-Token: {private_app_password}
  • Content-Type: application/json
curl -X GET \
  'https://your-store-name.myshopify.com/admin/api/2024-04/products.json' \
  -H 'X-Shopify-Access-Token: shppa_YOUR_PRIVATE_APP_PASSWORD' \
  -H 'Content-Type: application/json'

For OAuth 2.0 authenticated requests, the X-Shopify-Access-Token header would contain the access token obtained through the OAuth flow. For Storefront API requests using a public access token, the token is typically included in a GraphQL query header or directly in the client-side configuration, as detailed in the Shopify Storefront API documentation.

Security best practices

Properly securing your Shopify API credentials and managing authentication flows is critical to protect merchant data and maintain the integrity of your applications. Adhering to these best practices helps mitigate common security risks:

  1. Securely Store Credentials: Never hardcode API keys, client secrets, or access tokens directly in your application's source code. Use environment variables, secure configuration files, or dedicated secret management services (e.g., Google Cloud Secret Manager, AWS Secrets Manager) for production environments.
  2. Limit Scopes to Least Privilege: When requesting API access scopes (for OAuth) or configuring private app permissions, grant only the minimum necessary permissions required for your application's functionality. Over-provisioning permissions creates unnecessary security risks.
  3. Protect Callback URLs: For OAuth applications, ensure your redirect URI (callback URL) is registered accurately in the Shopify Partner Dashboard and uses HTTPS. Validate the state parameter during the OAuth callback to prevent cross-site request forgery (CSRF) attacks.
  4. Validate Webhooks: If your application receives webhooks from Shopify, always verify the webhook's authenticity using the X-Shopify-Hmac-Sha256 header. This ensures that the webhook originated from Shopify and has not been tampered with. The Shopify webhook security guide provides detailed instructions.
  5. Encrypt Data in Transit: Always use HTTPS for all communication with Shopify APIs. This encrypts data, protecting it from eavesdropping and tampering during transit. Shopify APIs enforce HTTPS automatically.
  6. Regularly Rotate Credentials: While Shopify access tokens are typically long-lived, consider mechanisms for rotating credentials (e.g., private app passwords) periodically, especially in high-security environments.
  7. Implement Error Handling and Logging: Implement robust error handling for authentication failures and log relevant security events. This helps in detecting and responding to potential unauthorized access attempts.
  8. Sanitize and Validate Inputs: Always sanitize and validate any user-supplied input before using it in API requests to prevent injection attacks and other vulnerabilities.

By following these guidelines, developers can build secure and reliable integrations with the Shopify API, protecting both their applications and the merchant data they access.