Skip to content

Instantly share code, notes, and snippets.

@rjaus
Created March 9, 2018 00:54
Show Gist options
  • Save rjaus/2dd34906cfa6fac9c5a0181404d14850 to your computer and use it in GitHub Desktop.
Save rjaus/2dd34906cfa6fac9c5a0181404d14850 to your computer and use it in GitHub Desktop.
Xero Webhooks ITR Example for Ruby Sintra
require 'sinatra'
require 'base64'
require 'openssl'
post '/webhook' do
payload = request.body.read
key = "WEBHOOKS_KEY"
signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), key, payload)).strip()
puts request.env['HTTP_X_XERO_SIGNATURE']
puts signature
if (request.env['HTTP_X_XERO_SIGNATURE'] == signature)
status = 200
else
status = 401
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment