Skip to content

Instantly share code, notes, and snippets.

@msmithstubbs
Created June 8, 2016 04:22
Show Gist options
  • Save msmithstubbs/a3191926264061fa5ef37df5a1674459 to your computer and use it in GitHub Desktop.
Save msmithstubbs/a3191926264061fa5ef37df5a1674459 to your computer and use it in GitHub Desktop.
Verifying a Back in Stock webhook
SHARED_SECRET = 'your_back_in_stock_api_key'
def verify_webhook(data, signature)
digest = OpenSSL::Digest::Digest.new('sha256')
calculated_hmac = Base64.encode64(OpenSSL::HMAC.digest(digest, SHARED_SECRET, data)).strip
calculated_hmac == signature
end
signature = request.headers["X-BIS-Signature"]
data = request.body
if verify_webhook(data, signature)
puts "Verified"
else
puts "Webhook signature doesn't match"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment