Skip to content

Verifying webhooks #312

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

Closed
aaronn opened this issue Jun 23, 2024 · 2 comments · Fixed by #321
Closed

Verifying webhooks #312

aaronn opened this issue Jun 23, 2024 · 2 comments · Fixed by #321

Comments

@aaronn
Copy link

aaronn commented Jun 23, 2024

It looks like only the javascriptand golang version of the client libraries have webhook validation right now. Would be great if this came to the Python library.

mattt added a commit that referenced this issue Jul 5, 2024
Resolves #312

---------

Signed-off-by: Mattt Zmuda <[email protected]>
@mattt mattt closed this as completed in #321 Jul 5, 2024
@mattt
Copy link
Contributor

mattt commented Jul 5, 2024

Hi @aaronn. That's a great suggestion! I just added this with #321 and #322, which are now available in 0.28.0.

import replicate

secret = replicate.webhooks.default.secret()

replicate.webhooks.validate(request=request, secret=secret)

@maximilianvb
Copy link

Hi, if anyone else confused about how to use this with python fastapi here is some code that works for me:

@app.post("/replicate-webhook")
async def replicate_webhook(request: Request, task_id: str = Query(...)):
    body = await request.body()
    body = body.decode()
    # Get the headers
    headers = dict(request.headers)
    # Validate the webhook
    secret = replicate.webhooks.default.secret()

    replicate.webhooks.validate(body=body, headers=headers, secret=secret)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants