Skip to content

Commit

Permalink
Propagate JSON decoding error on webhook event verification in Java (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dvacca-onfido authored Feb 18, 2025
1 parent cab4b26 commit 986e957
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ public class WebhookEventVerifier {
* @param rawEventBody the raw event body
* @param hexSignature the hex signature
* @return the webhook event
* @throws OnfidoInvalidSignatureError the onfido exception
* @throws OnfidoInvalidSignatureError on verification error
* @throws JsonParseException on JSON parsing error
*/
public WebhookEvent readPayload(String rawEventBody, String hexSignature)
throws OnfidoInvalidSignatureError {
throws OnfidoInvalidSignatureError, JsonParseException {
Mac sha256Hmac;
SecretKeySpec secretKey;
Expand All @@ -100,14 +101,10 @@ public class WebhookEventVerifier {
throw new OnfidoInvalidSignatureError("Invalid signature for webhook event");
}

try {
JsonReader jsonReader = new JsonReader(new StringReader(rawEventBody));
jsonReader.setLenient(true);
JsonReader jsonReader = new JsonReader(new StringReader(rawEventBody));
jsonReader.setLenient(true);

return gson.fromJson(jsonReader, WebhookEvent.class);
} catch (JsonParseException e) {
throw new OnfidoInvalidSignatureError("Invalid payload for webhook event", e);
}
return gson.fromJson(jsonReader, WebhookEvent.class);
}

private String encodeHexString(byte[] byteArray) {
Expand Down

0 comments on commit 986e957

Please sign in to comment.