Created
April 28, 2020 15:25
-
-
Save tcannonfodder/f7eab130be6e13aed1ce82d222afb0eb to your computer and use it in GitHub Desktop.
Noko Webhooks Tester server
This file contains 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 '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