-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdropbox-event_callback_helper.mustache
46 lines (37 loc) · 1.2 KB
/
dropbox-event_callback_helper.mustache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
=begin
{{> api_info}}
=end
require 'openssl'
module Dropbox
end
module Dropbox::Sign
class EventCallbackHelper
EVENT_TYPE_ACCOUNT_CALLBACK = "account_callback"
EVENT_TYPE_APP_CALLBACK = "app_callback"
# Verify that a callback came from HelloSign.com
#
# @param [String] api_key
# @param [EventCallbackRequest] event_callback
# @return bool
def self.is_valid(api_key, event_callback)
hash = OpenSSL::HMAC.hexdigest(
"SHA256",
api_key,
"#{event_callback.event.event_time}#{event_callback.event.event_type}",
)
return event_callback.event.event_hash === hash
end
# Identifies the callback type, one of "account_callback" or "app_callback".
# "app_callback" will always include a value for "reported_for_app_id"
#
# @param [EventCallbackRequest] event_callback
# @return string
def self.get_callback_type(event_callback)
metadata = event_callback.event.event_metadata || EventCallbackRequestEventMetadata.new
if metadata.nil? || metadata.reported_for_app_id.nil? || metadata.reported_for_app_id.empty?
return EVENT_TYPE_ACCOUNT_CALLBACK
end
return EVENT_TYPE_APP_CALLBACK
end
end
end