WebhookVerifier

class WebhookVerifier(secret: String, toleranceSeconds: Long = 300)

Verifies OpenAI's Standard Webhooks HMAC-SHA256 signatures over the unmodified body bytes. Supply a trusted current Unix time on every call. Timestamp tolerance limits replay age; applications must additionally deduplicate event IDs when processing deliveries.

Parameters

secret

base64 signing key, with or without the whsec_ prefix.

toleranceSeconds

maximum delivery timestamp age or future clock skew, inclusive.

Constructors

Link copied to clipboard
constructor(secret: String, toleranceSeconds: Long = 300)

Functions

Link copied to clipboard
fun unwrap(payload: ByteArray, headers: Map<String, String>, nowSeconds: Long): WebhookEvent

Verifies the unmodified body, then parses its UTF-8 JSON event while retaining unknown fields. Signature errors are distinct from invalid UTF-8, JSON or event-shape errors.

Link copied to clipboard
fun verify(payload: ByteArray, headers: Map<String, String>, nowSeconds: Long)

Verifies headers and the original bytes before parsing JSON. Header names are case-insensitive. Supported signature versions are v1 (HMAC-SHA256).