Skip to main content

This module provides a utility function to verify the authenticity of data received from Shopify webhooks. It uses HMAC (Hash-based Message Authentication Code) with SHA-256 hashing to ensure that the data has not been tampered with in transit.

Project description

Shopify Webhook Verification

This module provides a utility function to verify the authenticity of data received from Shopify webhooks. It uses HMAC (Hash-based Message Authentication Code) with SHA-256 hashing to ensure that the data has not been tampered with in transit.

Function Description

verify is a function that computes an HMAC for the given data and compares it with the HMAC provided in the Shopify webhook header. It's designed to be a robust and secure way to validate the integrity and authenticity of the data received from Shopify.

Arguments

  • data_bytes (bytes): The raw data for which the HMAC is being verified.
  • shared_secret (Union[bytes, bytearray]): The secret key used for HMAC generation.
  • hmac_sha256 (AnyStr): The base64 encoded HMAC string received in the Shopify webhook header.

Returns

bool: Returns True if the HMAC matches, False otherwise.

Installation

No specific installation steps required, just ensure you have Python 3.x installed.

Usage

Here's a basic usage example:

# The raw data received from Shopify
raw_data_as_bytes = request.data  # Replace with actual request data

# The HMAC header received from Shopify
hmac_sha256 = request.headers.get("X-Shopify-Hmac-Sha256")  # Replace with actual header

# The secret key provided by Shopify
shared_secret = "your_shared_secret_here".encode("utf-8")

# Perform verification
verified = verify(
    data_bytes=raw_data_as_bytes,
    hmac_sha256=hmac_sha256,
    shared_secret=shared_secret,
)

if verified:
    print("Verification successful!")
else:
    print("Verification failed!")

Logging

The function uses Python's built-in logging to report its status and errors. You can configure the logging level as per your requirement.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

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

Source Distribution

verifyshopify-0.1.6.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

verifyshopify-0.1.6-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file verifyshopify-0.1.6.tar.gz.

File metadata

  • Download URL: verifyshopify-0.1.6.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.6 Darwin/23.1.0

File hashes

Hashes for verifyshopify-0.1.6.tar.gz
Algorithm Hash digest
SHA256 fbd017904854d9f3a70cacd82d7efeee651d4692c63bae0cbc651cc63f740dee
MD5 3f6b105221136a2f840e5f5ed40e7538
BLAKE2b-256 09e04a7e7c4624b1864761b3eb6b57af09f222d80535a42e68c31bd43a43d794

See more details on using hashes here.

File details

Details for the file verifyshopify-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: verifyshopify-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.6 Darwin/23.1.0

File hashes

Hashes for verifyshopify-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f82dea01b9f21fdc5262cd14cb904cfcbf4c8bc1c71ba8e43880c26c443cef0f
MD5 9c25d88450e0f8d1b0df60a9193d0787
BLAKE2b-256 4d40e26c3b54a5a9842904de20c88d100c9b92ec44b1b70e85583442545fc7cc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page