Skip to content

Instantly share code, notes, and snippets.

@joshbeckman
Last active October 10, 2015 17:02
Show Gist options
  • Save joshbeckman/2c528833860b5d1e5c34 to your computer and use it in GitHub Desktop.
Save joshbeckman/2c528833860b5d1e5c34 to your computer and use it in GitHub Desktop.
var crypto = require('crypto'),
secret = 'OUR_APP_SHARED_SECRET',
message = req.rawBody.toString('utf8'),
digest = crypto.createHmac('SHA256', secret)
.update(new Buffer(message, 'utf8'))
.digest('base64');
console.log(digest == req.headers['X-Shopify-Hmac-Sha256']);
// true
@joshbeckman
Copy link
Author

Technically, line #5 doesn't need to be a Buffer for crypto to hash your message, but it is required when unicode characters are in the req.body payload. Otherwise, the digest will not match the provided hmac hash from Shopify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment