Skip to content

Commit 8919a2b

Browse files
Update Webhook.md
Updated the document for webhook secret key
1 parent efa5e2e commit 8919a2b

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

docs/docs/help/Settings/Webhook.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,134 @@ Suppose you're using OpenSign to collect eSignatures:
4040

4141
---
4242

43+
## 🧭 How to Create a Webhook Security Key
44+
45+
A **Webhook Security Key** (also called a webhook secret) is a shared secret used to verify that webhook requests are genuinely sent by OpenSign and have not been tampered with.
46+
47+
### Steps to Create a Webhook Security Key
48+
49+
1. Log in to your **OpenSign** account.
50+
2. Navigate to **Settings → Webhooks**.
51+
3. Add or edit a webhook endpoint.
52+
4. Generate a **Security Key** (or manually enter a strong secret).
53+
- Use a long, random string (at least 32 characters).
54+
- Example: `a50a904a2a329d761781dac27c984416a07396736ac5588b62c6fe226538fbca`
55+
5. Save the webhook configuration.
56+
57+
⚠️ **Important:** Store this key securely. Do not expose it in client-side code or public repositories.
58+
59+
---
60+
61+
## 🔐 How the Webhook Security Key Works
62+
63+
OpenSign signs every webhook request using your security key.
64+
65+
### High-level Flow
66+
67+
1. An event occurs (e.g. create document, document viewed, signed, completed, and declined).
68+
2. OpenSign sends a webhook request to your configured endpoint.
69+
3. OpenSign generates a signature using:
70+
- The **raw request payload**
71+
- Your **webhook security key**
72+
- The **HMAC-SHA256** algorithm
73+
4. The generated signature is sent in the request header:
74+
75+
```
76+
x-webhook-signature
77+
```
78+
79+
5. Your server recomputes the signature using the same payload and secret.
80+
6. If both signatures match, the request is verified as authentic.
81+
82+
---
83+
84+
## 🧪 Signature Verification Example (Node.js)
85+
86+
Below is a sample implementation to verify the webhook signature on your server.
87+
88+
```js
89+
const crypto = require("crypto");
90+
91+
function verifySignature(req, secret) {
92+
const receivedSignature = req.headers["x-webhook-signature"];
93+
const payload = req.body;
94+
95+
const expectedSignature = crypto
96+
.createHmac("sha256", secret)
97+
.update(JSON.stringify(payload))
98+
.digest("hex");
99+
100+
return receivedSignature === expectedSignature;
101+
}
102+
```
103+
104+
### Usage Example
105+
106+
```js
107+
const isValid = verifySignature(req, WEBHOOK_SECRET);
108+
109+
if (!isValid) {
110+
return res.status(401).send("Invalid webhook signature");
111+
}
112+
113+
// Process webhook event
114+
```
115+
116+
---
117+
118+
## 📦 Sample Webhook Payload
119+
120+
```json
121+
{
122+
"event": "viewed",
123+
"objectId": "d4LP0kKezS",
124+
"type": "request-sign",
125+
"file": "https://...pdf",
126+
"name": "Nu-international-application-form",
127+
"note": "Please review and sign this document",
128+
"signers": [
129+
{
130+
"name": "Mathew Wade",
131+
"email": "mathew.wade@opensignlabs.com"
132+
},
133+
{
134+
"name": "Steve Broad",
135+
"email": "steve.Broad@opensignlabs.com",
136+
"phone": "2678288322"
137+
}
138+
],
139+
"viewedBy": "mathew.wade@opensignlabs.com",
140+
"viewedAt": "Wed, 17 Dec 2025 13:46:05 GMT+5:30",
141+
"createdAt": "Wed, 17 Dec 2025 13:36:40 GMT+5:30"
142+
}
143+
```
144+
145+
The corresponding signature is sent in the request header:
146+
147+
```
148+
x-webhook-signature: bcf57b06dde0c030d9423639824bad17ab7dd09ea3bf0a743773b95254ecf78e
149+
```
150+
---
151+
152+
## ✅ Best Practices
153+
154+
- Always verify the webhook signature before processing the payload.
155+
- Use the **raw request body** for signature calculation (avoid modifying it).
156+
- Rotate your webhook security key periodically.
157+
- Return a **2xx** HTTP status only after successful verification.
158+
159+
---
160+
161+
## 🧩 Common Issues
162+
163+
- **Signature mismatch**: Ensure the payload is stringified exactly as received.
164+
- **Missing header**: Confirm `x-webhook-signature` is present in the request.
165+
- **Wrong secret**: Verify the same security key is used on both sides.
166+
167+
---
168+
169+
This mechanism ensures webhook requests are secure, tamper-proof, and trustworthy.
170+
43171
## 🧪 Sandbox Webhook
44172

45173
- You can also add webhook for the **Sandbox** environment on the same page.

0 commit comments

Comments
 (0)