Skip to content

Commit 180768a

Browse files
committed
add signature verification
1 parent 333b078 commit 180768a

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

.fernignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ README.md
44
assets/
55

66
src/webflow/oauth.py
7+
src/webflow/signature.py

src/webflow/signature.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# If we can I'd like to move this to the webhooks client wrapper,
2+
# but I can't find the Fern generation.yml to extend the client
3+
# according to documentation included here:
4+
# https://buildwithfern.com/learn/sdks/capabilities/custom-code
5+
import hmac
6+
import hashlib
7+
from collections.abc import Mapping
8+
9+
def verify(headers: Mapping, body:str , secret: str):
10+
# Normalize header format to account for different server implementations
11+
normalized_headers = {k.lower(): v for k, v in headers.items()}
12+
13+
message = f"{normalized_headers.get('x-webflow-timestamp', '')}:{body}".encode('utf-8')
14+
15+
generated_signature = hmac.new(
16+
key=secret.encode('utf-8'),
17+
msg=message,
18+
digestmod=hashlib.sha256
19+
).hexdigest()
20+
21+
return normalized_headers.get("x-webflow-signature", "") == generated_signature

0 commit comments

Comments
 (0)