# webhook validate in spring boot

**URL:** <https://devforum.zoom.us/t/webhook-validate-in-spring-boot/90675>\
**Category:** API and Webhooks\
**Tags:** webhooks\
**Created:** [June 22, 2023, 2:21pm UTC](https://devforum.zoom.us/t/webhook-validate-in-spring-boot/90675 "2023-06-22T14:21:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![teamnamanco](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/teamnamanco/32/49649_2.png) [@teamnamanco](https://devforum.zoom.us/u/teamnamanco)\
**Post date:** [June 22, 2023, 2:21pm UTC](https://devforum.zoom.us/t/webhook-validate-in-spring-boot/90675/1 "2023-06-22T14:21:54Z")

</div>

Hello, I have a question about webhook validate.

The current development environment is spring boot and java 17 environment, and I wrote the webbook validate code like the code below, but x-zm-signature keeps coming out differently, is it possible to check the sample code or code?

@Operation(hidden = true)  
@PostMapping(“/meeting-end”)  
public ResponseEntity\<Map\<String, String\>\> endZoomMeeting(@RequestBody MeetingEndWebhookReq zoomReq, HttpServletRequest request)  
throws JsonProcessingException {  
Map\<String, String\> payload = new HashMap\<\>();

```
    payload.put("plainToken", zoomReq.getPayload().getPlainToken());

    MeetingValidate validate = MeetingValidate.builder()
        .event(zoomReq.getEvent())
        .payload(payload)
        .event_ts(zoomReq.getEvent_ts())
        .build();

    ObjectMapper objectMapper = new ObjectMapper();

    String message = "v0:" + request.getHeader("x-zm-request-timestamp") + ":" + objectMapper.writeValueAsString(validate);
    String generatedSignature = generateSignature(message, secretKey);

    Map<String, String> response = new HashMap<>();
    log.info("message ===================== {}", message);
    log.info("json ======================== {}", objectMapper.writeValueAsString(validate));
    log.info("signature =================== {}", request.getHeader("x-zm-signature"));
    log.info("value ======================= {}", generatedSignature);

    if (request.getHeader("x-zm-signature").equals(generatedSignature)) {
        if (zoomReq.getEvent().equals("endpoint.url_validation")) {
            if (zoomReq.getEvent().equals("endpoint.url_validation")) {
                String plainToken = zoomReq.getPayload().getPlainToken();
                String hashForValidate = generateSignature(plainToken, secretKey);

                response.put("plainToken", plainToken);
                response.put("encryptedToken", hashForValidate);
                return ResponseEntity.status(HttpStatus.OK).body(response);
            }
        }
    }

    return ResponseEntity.status(HttpStatus.OK).body(response);

```

// return ResponseEntity.ok(Body.success(meetingService.quitMeeting(request)));  
}

```
private String generateSignature(String message, String secretToken) {
    try {
        SecretKeySpec secretKeySpec = new SecretKeySpec(secretToken.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        sha256Hmac.init(secretKeySpec);

        byte[] hashBytes = sha256Hmac.doFinal(message.getBytes(StandardCharsets.UTF_8));
        return "v0=" + Hex.encodeHexString(hashBytes);
    } catch (NoSuchAlgorithmException | InvalidKeyException e) {
        e.printStackTrace();
        return null; // Handle the error case appropriately
    }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [June 25, 2024, 5:58am UTC](https://devforum.zoom.us/t/webhook-validate-in-spring-boot/90675/2 "2024-06-25T05:58:11Z")

</div>

Closed on June 25, 2024, 5:58am UTC

This topic was automatically closed 368 days after the last reply. New replies are no longer allowed.
