067e19fec9
* Attach webhook to http endpoint * Create internal webhook handler job * Fix delivery * Add webhook trigger * Index webhooks * Fix webhook connect * Webhook activation * Rename to TriggerWebhook * Save webhooks to index * Extend register payload * Revert attachSource * Add update webhook helper * Use crud interface for registration * Remove filter from params * Destructure options * Missing ohash dep * Chainable trigger filter * Optional request verification * Handler call with context * Update config on register success * Rename to webhookData * Add basic key-value store * Improve kv store * Webhook trigger UI * Webhook delivery UI * Some fixes * Airtable experiments * Fix tabs transitions * Only run register if config differs * Use subtasks for delivery * Missing dep * Error handing and fixes * Namespace cursor * Fix hmac verification * Gut Airtable * Lockfile * Template optional api key * Template event sources and icons * Template remove filter from params * Fix models template * Template fixme * Fix webhook trigger header * Actually send params for registration.. * Add back oauthed client * Verify signature header encoding param * Fix delivery context * Webhook create retry with prior delete * Webhook source type fixes * Webhook config merge * Update webhook icon * Verify webhook task options * Rename handler to generateEvents * Send event icons * Shopify with webhooks * Shopify job-catalog entry * Lockfile * Add webhook migration * Better icons * Type fixes * Make param type optional * Scope type * More examples * More schemas * Trigger catalog * Bump versions * Just a few more events they said * Simplify session and config * Typed serializer * Fix payload type * Remove unused getters * Reduce logging output * Rest resource tasks * Lockfile * Bump version * Remaining triggers * Fix event types * Fix import * Link from webhook trigger to http endpoint * Use rest resource tasks for crud * Fix rest save type * Improve KV types * Improve attach webhook logging * Make header schema more lenient * Fix save type again * Final error callback * Shorten keys * Remove ohash diff * Disable Airtable webhooks * Webhook environments * Fix shopify error import * Link to integration and http endpoint * Integration catalog entry * Disable oauth * Require api key, simplify client secret * Move trigger types * Update catalog example * Small KV endpoint refactor * Fix custom migration * Webhook environment migration * Improve crud types * Remove unused schema * Fix crud context type * KV limits and HTTP verbs * KV improvements * Jobless webhook delivery * Airtable delivery fixes * Make deliveries sexy again * Some docs * Fix payload types.. again * Final payload pass * Schema cleanup * Refactor handler service * Remove more stale schemas * registerJobNamespace import * Expose KV on TriggerClient * Remove dummy click handler * Remove unused components * Fix delivery pagination * Enable registration rerun button * Comment out registration route action handler * Rename KV as not tied to IO anymore * Swap api with trigger client * Disabled fields param * KV docs * Changeset * Shopify docs fixes
71 lines
2.7 KiB
Plaintext
71 lines
2.7 KiB
Plaintext
---
|
|
title: "verifyRequestSignature()"
|
|
description: "Verify webhook payloads when they're using common signing methods."
|
|
---
|
|
|
|
Most webhooks come with a signature in the request header. This signature is used to verify that the request is coming from the expected source. To verify you typically need to take the body of the payload, hash it and compare it with the signature in the header. You use a secret when you hash the payload to make sure that the payload hasn't been tampered with.
|
|
|
|
When using [HttpEndpoint](/sdk/http-endpoint) you are required to verify the payload. `verifyRequestSignature()` is a helper function that makes this easy for the majority of webhooks.
|
|
|
|
<RequestExample>
|
|
|
|
```typescript
|
|
const caldotcom = client.defineHttpEndpoint({
|
|
id: "cal.com",
|
|
source: "cal.com",
|
|
icon: "caldotcom",
|
|
verify: async (request) => {
|
|
//this is a useful helper function that can verify sha256 signatures
|
|
//each API has a different header name
|
|
return await verifyRequestSignature({
|
|
request,
|
|
//you can find the header name in the API's documentation
|
|
headerName: "X-Cal-Signature-256",
|
|
//you can find the secret in the Trigger.dev dashboard, on the HTTP endpoint page
|
|
secret: process.env.CALDOTCOM_SECRET!,
|
|
algorithm: "sha256",
|
|
});
|
|
},
|
|
});
|
|
```
|
|
|
|
</RequestExample>
|
|
|
|
## Parameters
|
|
|
|
<ResponseField name="options" required>
|
|
<Expandable title="options" defaultOpen>
|
|
<ResponseField name="request" type="Request" required>
|
|
The web request that you want to verify.
|
|
</ResponseField>
|
|
<ResponseField name="headerName" type="string" required>
|
|
The name of the header that contains the signature. E.g. `X-Cal-Signature-256`.
|
|
</ResponseField>
|
|
<ResponseField name="headerEncoding" type="BinaryToTextEncoding">
|
|
The header encoding. Defaults to `hex`.
|
|
</ResponseField>
|
|
<ResponseField name="secret" type="string" required>
|
|
The secret that you use to hash the payload. For HttpEndpoints this will usually originally
|
|
come from the Trigger.dev dashboard and should be stored in an environment variable.
|
|
</ResponseField>
|
|
<ResponseField name="algorithm" type="sha256" required>
|
|
The hashing algorithm that was used to create the signature. Currently only `sha256` is
|
|
supported.
|
|
</ResponseField>
|
|
</Expandable>
|
|
</ResponseField>
|
|
|
|
## Returns
|
|
|
|
<ResponseField name="VerifyResult" required>
|
|
<Expandable defaultOpen>
|
|
<ResponseField name="success" type="boolean" required>
|
|
Whether the signature is valid or not
|
|
</ResponseField>
|
|
<ResponseField name="reason" type="string">
|
|
If `success` is false then you can provide the reason it failed. This is dealt with for you by
|
|
the `verifyRequestSignature()` function.
|
|
</ResponseField>
|
|
</Expandable>
|
|
</ResponseField>
|