Error validating webhook

The problem I’m having

Following the example to validate the webhook

auth_header = request.headers.get('authorization', None)
app_secret = os.environ['MY_DBT_CLOUD_AUTH_TOKEN'].encode('utf-8')
signature = hmac.new(app_secret, request_body, hashlib.sha256).hexdigest()
return signature == auth_header

and adapting it to a Django request framework request

auth_header = request.headers.get("Authorization", None)
    secret_key = dbt_config.get("secret_key", "").encode("utf-8")
    signature = hmac.new(
        secret_key, json.dumps(request.data).encode(), hashlib.sha256
    ).hexdigest()

I’m unable to receive matching signature and auth_header when I click “Test Endpoint” in the webhooks settings page. I am confident that I have the correct secret_key which I copied when I created the webhook and it was even present still when I clicked the Test Endpoint button.

Can you help?

The context of why I’m trying to do this

Adapt to django

What I’ve already tried

The above

Some example code or error messages

None, the tokens just don’t match

My bad, I found this blog post and fixed it using the separators.

signature = hmac.new(
        secret_key,
        json.dumps(request.data, separators=(",", ":")).encode(),
        hashlib.sha256,
    ).hexdigest()

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.