Webhooks

Verifying the service’s webhook deliveries.

A delivery is a POST of JSON with the header Luna-Signature: t=<seconds>,v1=<hex>: the HMAC-SHA256, keyed with the webhook’s secret, of <seconds>.<body>. Check it against the body exactly as received, before parsing it:

from lunaspace.webhooks import verify event = verify(secret, request.body, request.headers[“Luna-Signature”])

verify raises InvalidSignature for a delivery that is not the service’s, or that is older than tolerance seconds (a replay); it returns the event, parsed.

exception lunaspace.webhooks.InvalidSignature

The delivery’s signature does not hold, or is too old.

lunaspace.webhooks.signature(secret, timestamp, body)

The signature’s v1 of a body sent at timestamp (seconds since 1970).

Parameters:
Return type:

str

lunaspace.webhooks.verify(secret, body, header, *, tolerance=300, now=None)

The event of a delivery whose Luna-Signature header holds; InvalidSignature otherwise.

Parameters:
Return type:

dict[str, Any]