Skip to content

Instantly share code, notes, and snippets.

@marcguyer
Last active December 11, 2015 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcguyer/4565797 to your computer and use it in GitHub Desktop.
Save marcguyer/4565797 to your computer and use it in GitHub Desktop.
A Ruby example for validating a CheddarGetter webhook.
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