Skip to content

Commit da3d870

Browse files
author
Sergey Shelomentsev
committed
chore: updated readme
1 parent 7f55a3f commit da3d870

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,37 @@ public class SealedResults {
202202
```
203203
To learn more, refer to example located in [src/examples/java/com/fingerprint/example/SealedResults.java](src/examples/java/com/fingerprint/example/SealedResults.java).
204204

205+
## Webhook signature validation
206+
This SDK provides utility method for verifying the HMAC signature of the incoming webhook request.
207+
```java
208+
209+
@RestController
210+
class WebhookController {
211+
212+
@PostMapping("/api/webhook")
213+
@ResponseBody
214+
public String webhookHandler(@RequestBody String webhook, @RequestHeader HttpHeaders headers) {
215+
final String secret = System.getenv("WEBHOOK_SIGNATURE_SECRET");
216+
if (secret == null || secret.isEmpty()) {
217+
return new ResponseEntity<String>("Secret key is not configured", HttpStatus.INTERNAL_SERVER_ERROR);
218+
}
219+
220+
final String header = headers.get("fpjs-event-signature");
221+
if (header == null || header.size == 0) {
222+
return new ResponseEntity<String>("Missing fpjs-event-signature header", HttpStatus.BAD_REQUEST);
223+
}
224+
final String signature = header[0];
225+
226+
final boolean isValidSignature = Webhook.isValidWebhookSignature(signature, data.getBytes(StandardCharsets.UTF_8), secret);
227+
if (!isValidSignature) {
228+
return new ResponseEntity<String>("Webhook signature is not valid", HttpStatus.BAD_REQUEST);
229+
}
230+
231+
return new ResponseEntity<String>("Webhook received", HttpStatus.OK);
232+
}
233+
}
234+
```
235+
205236
## Documentation for API Endpoints
206237

207238
All URIs are relative to *https://api.fpjs.io*

0 commit comments

Comments
 (0)