The Webhooks API provides methods for verifying webhook signatures and constructing validated event objects from webhook payloads.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/workos/workos-node/llms.txt
Use this file to discover all available pages before exploring further.
Construct Event
Verifies the webhook signature and constructs a validated event object.Parameters
The raw webhook payload received from WorkOS.
The value of the
workos-signature header from the webhook request.Your webhook secret key from the WorkOS dashboard.
Time tolerance in milliseconds for validating the timestamp. Defaults to 180000 (3 minutes). Events with timestamps outside this tolerance window will be rejected to prevent replay attacks.
Response
Returns a Promise that resolves to anEvent object with the following properties:
Unique identifier for the event.
The event type (e.g.,
user.created, connection.activated, dsync.user.created).The event payload containing the relevant resource data. The structure varies based on the event type.
ISO 8601 timestamp when the event was created.
Additional context about the event.
Error Handling
The method throws aSignatureVerificationException if:
- The signature header is missing or malformed
- The timestamp is outside the tolerance window
- The computed signature doesn’t match the provided signature
Verify Header
Verifies a webhook signature without constructing the event object.Parameters
The raw webhook payload.
The
workos-signature header value.Your webhook secret key.
Time tolerance in milliseconds.
Response
Returns a Promise that resolves totrue if the signature is valid.
Compute Signature
Computes the expected signature for a webhook payload. Useful for testing and debugging.Parameters
The timestamp from the webhook signature header.
The webhook payload object.
Your webhook secret key.
Response
Returns a Promise that resolves to the computed HMAC signature string.Get Timestamp and Signature Hash
Parses the signature header to extract the timestamp and signature hash.Parameters
The
workos-signature header value in format t=<timestamp>,v1=<signature>.Response
Returns a tuple[timestamp: string, signatureHash: string].
Webhook Verification Examples
Express.js
Next.js API Route
Fastify
Event Types
TheEvent object returned by constructEvent can be one of many types. Common event types include:
- Authentication:
authentication.sso_succeeded,authentication.password_failed, etc. - Users:
user.created,user.updated,user.deleted - Organizations:
organization.created,organization.updated,organization.deleted - Connections:
connection.activated,connection.deactivated,connection.deleted - Directory Sync:
dsync.user.created,dsync.group.created, etc. - Sessions:
session.created,session.revoked - Invitations:
invitation.created,invitation.accepted
Security Best Practices
- Always verify webhook signatures before processing events
- Use a reasonable tolerance window (3-5 minutes) to prevent replay attacks
- Store your webhook secret securely as an environment variable
- Use raw body parsing for webhook endpoints to ensure signature verification works correctly
- Return a 200 status code quickly and process events asynchronously if needed
- Log failed verification attempts for security monitoring