Skip to content

Commit 1c929c7

Browse files
docs: Add webhook validation section to migration guide in TS (box/box-codegen#637) (#460)
1 parent f0c0d91 commit 1c929c7

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "a2387ff", "specHash": "4ccce13", "version": "1.10.0" }
1+
{ "engineHash": "d26e99e", "specHash": "4ccce13", "version": "1.10.0" }

migration-guide.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [Configuration](#configuration)
2929
- [As-User header](#as-user-header)
3030
- [Custom Base URLs](#custom-base-urls)
31+
- [Webhook validation](#webhook-validation)
3132

3233
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3334

@@ -577,3 +578,35 @@ const newClient = client.withCustomBaseUrls({
577578
oauth2Url: 'https://account.box.com/api/oauth2',
578579
});
579580
```
581+
582+
## Webhook validation
583+
584+
Webhook validation is used to validate a webhook message by verifying the signature and the delivery timestamp.
585+
586+
**Legacy (`Box Node SDK`):**
587+
588+
In the old SDK, you could pass the `body` as either a `JSON` object or a `string`, and it would return a `boolean` value indicating whether the message was valid.
589+
590+
```typescript
591+
let isValid = BoxSDK.validateWebhookMessage(
592+
body,
593+
headers,
594+
primaryKey,
595+
secondaryKey,
596+
);
597+
```
598+
599+
**Modern (`Box TypeScript SDK`):**
600+
601+
In the new SDK, the `WebhooksManager.validateMessage()` method requires the `body` to be of type `string`.
602+
So if the body is in `JSON` type, you must convert it to a `string` using `JSON.stringify(body)` before calling `validateMessage()`.
603+
604+
```typescript
605+
let stringBody = JSON.stringify(body);
606+
let isValid = await WebhooksManager.validateMessage(
607+
stringBody,
608+
headers,
609+
primaryKey,
610+
{ secondaryKey: secondaryKey } satisfies ValidateMessageOptionalsInput,
611+
);
612+
```

0 commit comments

Comments
 (0)