Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Webhook validation on Python

Webhook validation on Python

lucasalvessouza
Shopify Partner
1 0 0

I am using python + falcon, and I have the following code to validate my webhook request:

 

```

def validate_shopify_webhook(self, req, res):
  shopify_secret = '...'
  hmac_header = req.get_header('X-Shopify-Hmac-Sha256')
  raw_body = req.bounded_stream.read().decode('utf-8')

  hash_code = hmac.new(
    shopify_secret.encode('utf-8'),
    raw_body.encode('utf-8'),
    hashlib.sha256
  ).digest()

  calculated_hmac = base64.b64encode(hash_code).decode('utf-8')

  print(f"Generated HMAC: {calculated_hmac.encode('utf-8')}")
  print(f"Received HMAC: {hmac_header.encode('utf-8')}")

  return hmac.compare_digest(calculated_hmac.encode('utf-8'), hmac_header.encode('utf-8'))

 

```

 

I am always receiving False. Any clue?

Replies 0 (0)