You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We provide helper methods for verifying that a webhook request came from Finch, and not a malicious third party.
147
+
148
+
You can use `finch.webhooks.verify_signature(body: string, headers, secret?) -> None` or `finch.webhooks.unwrap(body: string, headers, secret?) -> Payload`,
149
+
both of which will raise an error if the signature is invalid.
150
+
151
+
Note that the "body" parameter must be the raw JSON string sent from the server (do not parse it first).
152
+
The `.unwrap()` method can parse this JSON for you into a `Payload` object.
153
+
154
+
For example, in [FastAPI](https://fastapi.tiangolo.com/):
155
+
156
+
```py
157
+
@app.post('/my-webhook-handler')
158
+
asyncdefhandler(request: Request):
159
+
body =await request.body()
160
+
secret = os.environ['FINCH_WEBHOOK_SECRET'] # env var used by default; explicit here.
When the library is unable to connect to the API (e.g., due to network connection problems or a timeout), a subclass of `finch.APIConnectionError` is raised.
0 commit comments