diff --git a/README.md b/README.md index 2f027a4..8da7c90 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ SmoothCodeAuth.new(request_hmac, client_secret).dashboard_request?(shop) # retur require 'smoothcode' # SmoothCode sends hmac in the Authorization Header of the request -# It is hmac of the webhook data signed by your App Client Secret +# It is hmac of the webhook id signed by your App Client Secret SmoothCodeAuth.new(request_hmac, client_secret).webhook_request?(webhook_data) # returns True if the request is valid ``` diff --git a/lib/smoothcode/auth.rb b/lib/smoothcode/auth.rb index 87aff64..a0aedfd 100644 --- a/lib/smoothcode/auth.rb +++ b/lib/smoothcode/auth.rb @@ -1,5 +1,4 @@ require_relative 'utils' -require 'json' class SmoothCodeAuth def initialize(request_hmac, client_secret) @@ -12,6 +11,9 @@ def dashboard_request?(shop) end def webhook_request?(webhook_data) - generate_hmac(@client_secret, webhook_data.to_json) == @request_hmac + webhook_data = webhook_data.transform_keys(&:to_sym) + webhook_id = webhook_data[:id] + + generate_hmac(@client_secret, webhook_id.to_s) == @request_hmac end end diff --git a/smoothcode.gemspec b/smoothcode.gemspec index 8b5a74b..c0b731c 100644 --- a/smoothcode.gemspec +++ b/smoothcode.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'smoothcode' - s.version = '0.0.2' + s.version = '0.0.3' s.summary = 'Ruby client to interact with SmoothCode' s.description = 'Ruby client to interact with SmoothCode' s.authors = ['SmoothCode']