Skip to content

Instantly share code, notes, and snippets.

@houmanka
Created February 2, 2018 15:13
Show Gist options
  • Save houmanka/65bb3936ed4bbbc8b3cee80b38877d02 to your computer and use it in GitHub Desktop.
Save houmanka/65bb3936ed4bbbc8b3cee80b38877d02 to your computer and use it in GitHub Desktop.
xero_hook.rb
require 'rubygems'
require 'base64'
require 'openssl'
require 'json'
require 'sinatra'
require 'logger'
require 'pry'
logger = Logger.new(STDOUT)
SHARED_SECRET = "MY_KEY"
post '/' do
request.body.rewind
data = request.body.read
hmac_header = request.env["HTTP_X_XERO_SIGNATURE"]
if hmac_header != nil
calculated_hmac = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', SHARED_SECRET, data))
logger.info('calculated_hmac') { calculated_hmac }
logger.info('hmac_header') { hmac_header }
logger.info('data') { data.inspect }
if calculated_hmac == hmac_header
status 200
else
status 401
end
else
status 401
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment