Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: verify webhook signature helper #3078

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions docs-v2/guides/verify-webhooks-from-nango.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ sidebarTitle: 'Verify webhooks from Nango'
description: 'Step-by-step guide on how to verify the signatures of webhooks from Nango.'
---

Validate webhook provenance by looking at the `X-Nango-Signature` header.
Validate webhook provenance by looking at the `X-Nango-Signature` header.

It's a SHA-256 hash generated using the secret key found in the _Environment Settings_ in the Nango UI.
It's a SHA-256 hash generated using the secret key found in the _Environment Settings_ in the Nango UI.

The webhook signature can be generated with the following code:

<Tabs>

<Tab title="Node SDK">

```typescript
async (req, res) => {
const signature = req.headers['x-nango-signature'];
const isValid = nango.verifyWebhookSignature(signature, req.body);
}
```
</Tab>

<Tab title="Javascript/Typescript">

```typescript
Expand Down Expand Up @@ -124,4 +134,4 @@ $hash = hash('sha256', $signature);

</Tabs>

Only accept a webhook if the `X-Nango-Signature` header value matches the webhook signature.
Only accept a webhook if the `X-Nango-Signature` header value matches the webhook signature.
15 changes: 15 additions & 0 deletions docs-v2/reference/sdks/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,21 @@ const { data } = await nango.createConnectSession({
```
</Expandable>


# Webhook

### Verify Webhook Signature

Asserts that a Webhook is coming from Nango's backend.

```js
async (req, res) => {
const signature = req.headers['x-nango-signature'];
const isValid = nango.verifyWebhookSignature(signature, req.body);
}
```


<Tip>
**Questions, problems, feedback?** Please reach out in the [Slack community](https://nango.dev/slack).
</Tip>
Loading