Repository navigation
Expand file tree
/
Copy pathEventCallbackHelper.java
More file actions
63 lines (54 loc) · 2.17 KB
/
Copy pathEventCallbackHelper.java
File metadata and controls
63 lines (54 loc) · 2.17 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Dropbox Sign API
* Dropbox Sign v3 API
*
* The version of the OpenAPI document: 3.0.0
* Contact: apisupport@hellosign.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package com.dropbox.sign;
import com.dropbox.sign.model.EventCallbackRequest;
import com.dropbox.sign.model.EventCallbackRequestEventMetadata;
import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;
@javax.annotation.Generated(
value = "org.openapitools.codegen.languages.JavaClientCodegen",
comments = "Generator version: 7.26.0")
public class EventCallbackHelper {
public static final String EVENT_TYPE_ACCOUNT_CALLBACK = "account_callback";
public static final String EVENT_TYPE_APP_CALLBACK = "app_callback";
private EventCallbackHelper() {}
/**
* Verify that a callback came from HelloSign.com
*
* @param apiKey
* @param eventCallback
* @return a boolean value indicating whether the callback event is valid
*/
public static boolean isValid(String apiKey, EventCallbackRequest eventCallback) {
return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, apiKey)
.hmacHex(
eventCallback.getEvent().getEventTime()
+ eventCallback.getEvent().getEventType())
.equals(eventCallback.getEvent().getEventHash());
}
/**
* Identifies the callback type, one of "account_callback" or "app_callback".
*
* <p>"app_callback" will always include a value for "reported_for_app_id"
*
* @param eventCallback
*/
public static String getCallbackType(EventCallbackRequest eventCallback) {
EventCallbackRequestEventMetadata metadata = eventCallback.getEvent().getEventMetadata();
if (metadata == null
|| metadata.getReportedForAppId() == null
|| metadata.getReportedForAppId().isEmpty()) {
return EventCallbackHelper.EVENT_TYPE_ACCOUNT_CALLBACK;
}
return EventCallbackHelper.EVENT_TYPE_APP_CALLBACK;
}
}