Created
June 8, 2016 04:22
-
-
Save msmithstubbs/a3191926264061fa5ef37df5a1674459 to your computer and use it in GitHub Desktop.
Verifying a Back in Stock webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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