Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
6 changes: 4 additions & 2 deletions lib/smoothcode/auth.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require_relative 'utils'
require 'json'

class SmoothCodeAuth
def initialize(request_hmac, client_secret)
Expand All @@ -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
2 changes: 1 addition & 1 deletion smoothcode.gemspec
Original file line number Diff line number Diff line change
@@ -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']
Expand Down