mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-09 01:14:23 -05:00
Update qbo_controller.rb
This commit is contained in:
@@ -11,6 +11,9 @@
|
|||||||
class QboController < ApplicationController
|
class QboController < ApplicationController
|
||||||
unloadable
|
unloadable
|
||||||
|
|
||||||
|
require 'openssl'
|
||||||
|
require 'Base64'
|
||||||
|
|
||||||
include AuthHelper
|
include AuthHelper
|
||||||
|
|
||||||
before_filter :require_user, :except => :qbo_webhook
|
before_filter :require_user, :except => :qbo_webhook
|
||||||
@@ -64,12 +67,16 @@ class QboController < ApplicationController
|
|||||||
# Quickbooks Webhook Callback
|
# Quickbooks Webhook Callback
|
||||||
def qbo_webhook
|
def qbo_webhook
|
||||||
|
|
||||||
#TODO check the payload
|
# check the payload
|
||||||
signature = request.headers['intuit-signature']
|
signature = request.headers['intuit-signature']
|
||||||
token = Setting.plugin_redmine_qbo['settingsWebhookToken']
|
key = Setting.plugin_redmine_qbo['settingsWebhookToken']
|
||||||
|
data = request.body.read
|
||||||
|
hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), key, data)).strip()
|
||||||
|
|
||||||
|
# proceed if the request is good
|
||||||
|
if hash.eql? signature
|
||||||
if request.headers['content-type'] == 'application/json'
|
if request.headers['content-type'] == 'application/json'
|
||||||
data = JSON.parse(request.body.read)
|
data = JSON.parse(data)
|
||||||
else
|
else
|
||||||
# application/x-www-form-urlencoded
|
# application/x-www-form-urlencoded
|
||||||
data = params.as_json
|
data = params.as_json
|
||||||
@@ -96,6 +103,9 @@ class QboController < ApplicationController
|
|||||||
else
|
else
|
||||||
obj.sync_by_id(id)
|
obj.sync_by_id(id)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
render nothing: true, status: 400
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Record that last time we updated
|
# Record that last time we updated
|
||||||
|
|||||||
Reference in New Issue
Block a user