Class WebhookSigner
java.lang.Object
com.kingsrook.qqq.backend.core.utils.webhooks.WebhookSigner
Signs webhook requests in the Standard Webhooks format
(https://www.standardwebhooks.com/).
The signed content is <id>.<timestamp>.<body>: the message id,
a dot, the Unix timestamp in seconds, a dot, then the exact body bytes. The
signature is HMAC-SHA256 with the secret's key, base64 encoded, and sent as
v1,<base64>. During a secret rotation every active secret signs, and
the signatures are separated by spaces, so a receiver holding either the old
or the new secret accepts the request.
Headers: webhook-id, webhook-timestamp,
webhook-signature.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionheaders(String messageId, Instant timestamp, byte[] body, List<WebhookSecret> secrets) The three signature headers for one request.static Stringsign(String messageId, long timestampSeconds, byte[] body, WebhookSecret secret) One base64 HMAC-SHA256 signature over<id>.<timestamp>.<body>.static StringsignatureHeader(String messageId, long timestampSeconds, byte[] body, List<WebhookSecret> secrets) Thewebhook-signaturevalue:v1,<sig>per secret, space separated.
-
Field Details
-
HEADER_ID
- See Also:
-
HEADER_TIMESTAMP
- See Also:
-
HEADER_SIGNATURE
- See Also:
-
VERSION_V1
-
-
Method Details
-
headers
public static Map<String,String> headers(String messageId, Instant timestamp, byte[] body, List<WebhookSecret> secrets) The three signature headers for one request.- Parameters:
messageId- the event id (stable across retries: it is the idempotency key)timestamp- when this attempt is sentbody- the exact bytes that are sentsecrets- the active secrets (one, or two during a rotation)
-
signatureHeader
public static String signatureHeader(String messageId, long timestampSeconds, byte[] body, List<WebhookSecret> secrets) Thewebhook-signaturevalue:v1,<sig>per secret, space separated. -
sign
public static String sign(String messageId, long timestampSeconds, byte[] body, WebhookSecret secret) One base64 HMAC-SHA256 signature over<id>.<timestamp>.<body>.
-