verify shopify webhook integrity - Node /Express Js

Highlighted
New Member
6 0 0

Hi Team,

I am working on verifying the integrity of shopify webhook and the digest generated is not similar to received headers Following https://gist.github.com/andjosh/5c4f0244914adfd312e4

function verifyShopifyHook(req) {
    var digest = crypto.createHmac('SHA256', SECRET)
            .update(new Buffer(req.body, 'utf8'))
            .digest('base64');   
    return digest === req.headers['X-Shopify-Hmac-Sha256'];
}

I was getting error - Unhandled promise rejection (rejection id: 2): TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object

So I changed to

   var msg = JSON.stringify(req.body);
   var digest = crypto.createHmac('sha256', APP_SHARED_SECRET)
                     .update(Buffer.from(msg,'utf8'))
                    .digest('base64');

digest generated is different then x-shopify-hmac-sha256

Any one has same issue ? or any idea how to resolve this

0 Likes