File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 77from collections .abc import Mapping
88
99def verify (headers : Mapping , body :str , secret : str ):
10+ """
11+ Verify that the signature on the webhook message is from Webflow
12+
13+ Documentation:
14+ https://developers.webflow.com/data/docs/working-with-webhooks#validating-request-signatures
15+
16+ Parameters:
17+ - headers : Mapping. The request headers in a Mapping-like object
18+
19+ - body : str. The request body as a UTF-8 encoded string
20+
21+ - secret : str. The secret key generated when creating the webhook or the OAuth client secret
22+ ---
23+ ```
24+ from fastapi import FastAPI, Request
25+ # ...
26+
27+ @app.post('/webhookEndpoint')
28+ async def webhook_endpoint_handler(
29+ request: Request,
30+ ):
31+ # Read the request body as a utf-8 encoded string
32+ body = (await request.body()).decode("utf-8")
33+
34+ # Extract the headers as Mapping-like object
35+ headers = request.headers
36+
37+ secret = get_secret()
38+
39+ verified = verify(
40+ headers=request.headers,
41+ body=(await request.body()).decode("utf-8"),
42+ secret=new_webhook.secretKey)
43+
44+ if verified:
45+ # ...process the request normally
46+ else:
47+ # ...handle unathenticated request
48+ ```
49+ """
50+
1051 # Normalize header format to account for different python server implementations
1152 # that may or may not normalize headers already
1253 normalized_headers = {k .lower (): v for k , v in headers .items ()}
You can’t perform that action at this time.
0 commit comments