Last active
December 11, 2015 07:19
-
-
Save marcguyer/4565797 to your computer and use it in GitHub Desktop.
A Ruby example for validating a CheddarGetter webhook.
This file contains hidden or 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
require 'openssl' | |
require 'digest' | |
product_key = 'YOUR_PRODUCT_KEY' | |
if !defined?(request) || request.nil? || request.env.nil? # not rails | |
# signature = {value of X-CG-SIGNATURE here} | |
# request_body = {value of raw request body here} | |
else # assume it's a ROR ActionController::AbstractRequest object | |
signature = request.env['X-CG-SIGNATURE'] | |
request_body = request.raw_post() | |
} | |
end | |
if signature.nil? | |
# p 'invalid1' | |
# invalid | |
end | |
token = Digest::MD5.hexdigest(request_body) | |
if signature != OpenSSL::HMAC.hexdigest('sha256', product_key, token) | |
# p 'invalid2' | |
#invalid | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment