You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+181Lines changed: 181 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -270,6 +270,187 @@ client.close();
270
270
271
271
The Schematic API supports many operations beyond these, accessible via the API modules on the client, `Accounts`, `Billing`, `Companies`, `Entitlements`, `Events`, `Features`, and `Plans`.
272
272
273
+
## Webhook Verification
274
+
275
+
Schematic can send webhooks to notify your application of events. To ensure the security of these webhooks, Schematic signs each request using HMAC-SHA256. The SDK provides utility functions to verify these signatures.
276
+
277
+
### Verifying Webhook Signatures
278
+
279
+
When your application receives a webhook request from Schematic, you should verify its signature to ensure it's authentic. The SDK provides simple functions to verify webhook signatures. Here's how to use them in different frameworks:
280
+
281
+
#### Express
282
+
283
+
```ts
284
+
importexpressfrom"express";
285
+
import {
286
+
verifyWebhookSignature,
287
+
WebhookSignatureError,
288
+
WEBHOOK_SIGNATURE_HEADER,
289
+
WEBHOOK_TIMESTAMP_HEADER,
290
+
} from"@schematichq/schematic-typescript-node";
291
+
292
+
// Note: Schematic webhooks use these headers:
293
+
// - X-Schematic-Webhook-Signature: Contains the HMAC-SHA256 signature
294
+
// - X-Schematic-Webhook-Timestamp: Contains the timestamp when the webhook was sent
295
+
296
+
const app =express();
297
+
298
+
// Use a middleware that captures raw body for signature verification
299
+
app.use(
300
+
"/webhooks/schematic",
301
+
express.json({
302
+
verify: (req, res, buf) => {
303
+
if (buf&&buf.length) {
304
+
(reqasany).rawBody=buf;
305
+
}
306
+
},
307
+
})
308
+
);
309
+
310
+
app.post("/webhooks/schematic", (req, res) => {
311
+
try {
312
+
const webhookSecret ="your-webhook-secret"; // Get this from the Schematic app
313
+
314
+
// Verify the webhook signature using the captured raw body
0 commit comments