Skip to content

Instantly share code, notes, and snippets.

@tcannonfodder
Created April 28, 2020 15:25
Show Gist options
  • Save tcannonfodder/f7eab130be6e13aed1ce82d222afb0eb to your computer and use it in GitHub Desktop.
Save tcannonfodder/f7eab130be6e13aed1ce82d222afb0eb to your computer and use it in GitHub Desktop.
Noko Webhooks Tester server
require 'sinatra'
require 'json'
require 'openssl'
def read_payload(secret, request)
body = request.body.read
push = JSON.parse(body)
given_signature = request.env["HTTP_X_NOKO_SIGNATURE"]
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), secret, body)
return halt 500, "Signatures didn't match!" unless Rack::Utils.secure_compare(signature, given_signature)
puts ({id: push["id"], type: push["type"], created_at: push["created_at"], entry_id: push["object"]["id"], signature: signature}).inspect
end
post '/payload' do
read_payload("abcd-1234", request)
end
post '/payload-2' do
read_payload("abcd-9876",request)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment