---
title: Webhooks
summary: A webhook subscription makes Tessera POST a signed JSON message to your server whenever a matching event happens in a realm, such as a user being created or disabled.
section: connect
order: 5
---
# Webhooks

A webhook subscription makes Tessera POST a signed JSON message to your server whenever a matching event happens in a realm, such as a user being created or disabled.

Use webhooks to keep your own records in step: create a profile when an invite is accepted, lock someone out when a user is disabled. They are not needed for sign-in. The event types are listed in [Webhook events](/docs/reference/webhook-events.md).

## Subscribe

Subscriptions are managed through the admin API with a token whose audience is `tessera-admin` and that carries `tessera:webhooks:write` (read: `tessera:webhooks:read`, delete: `tessera:webhooks:delete`). The admin API lives on the admin host. Send JSON with `Content-Type: application/json`.

```sh
curl -X POST https://login.kurthlabs.com/admin/v1/realms/acme/webhooks \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"destination_url": "https://app.example.com/webhooks/tessera", "event_type_pattern": "invite.*|user.*|access.*|session.*"}'
```

```json
{
  "id": "0194f3c2-6f1a-7c1e-9d2b-3a4b5c6d7e8f",
  "destination_url": "https://app.example.com/webhooks/tessera",
  "event_type_pattern": "invite.*|user.*|access.*|session.*",
  "hmac_secret_digest": "ba78...",
  "enabled": true,
  "hmac_secret": "B7c4..."
}
```

- `destination_url` must be a public `https` URL. Tessera does not follow redirects, and it refuses `localhost` and private, loopback, link-local or internal addresses, with `400` and the error code [`destination_not_public`](/errors/destination_not_public.md). A workspace has no allow list for such addresses. While you develop, use a deployed URL or a public tunnel to your machine. Register the final URL, since a redirect answer is a permanent failure.
- `event_type_pattern` defaults to `*` (everything). Separate patterns with `|`. A pattern matches an event type with `*` as a wildcard: `agent.*`, `user.created`, `user.created|user.deleted`.
- **The `hmac_secret` is shown once, in this answer.** Store it in your secret manager now. Later reads only show `hmac_secret_digest`, the SHA-256 of the secret.
- You may send your own `hmac_secret` of 32 to 512 bytes. Make it random.
- `PATCH` changes the URL, pattern or `enabled`. It never changes the secret.
- `POST .../webhooks/<id>/test` answers `202` and fires a `webhook.test_fired` event, which reaches your endpoint only if the pattern matches it (`*` does).

## What Tessera sends

```http
POST /webhooks/tessera HTTP/1.1
Content-Type: application/json
X-Tessera-Event: user.created
X-Tessera-Webhook-Id: 3f9c2a1e-8b7d-4c55-9e0a-1d2c3b4a5f60
X-Tessera-Timestamp: 1792929600
X-Tessera-Signature: sha256=9b1c...

{
  "event": "user.created",
  "realm_id": "0194f3c2-0000-7000-8000-000000000001",
  "occurred_at": "2026-10-25T12:00:00.123Z",
  "actor": { "type": "user", "id": "0194f3c2-6f1a-7c1e-9d2b-3a4b5c6d7e8f" },
  "subject": { "type": "user", "id": "0194f3c2-6f1a-7c1e-9d2b-3a4b5c6d7e8f" },
  "on_behalf_of": null,
  "metadata": { "user_id": "0194f3c2-6f1a-7c1e-9d2b-3a4b5c6d7e8f", "email": "ada@example.com", "via": "signup" }
}
```

| Header | Meaning |
| --- | --- |
| `X-Tessera-Event` | The event type |
| `X-Tessera-Webhook-Id` | Unique per delivery; a retry reuses it. Use it to deduplicate |
| `X-Tessera-Timestamp` | Unix seconds when this attempt was signed |
| `X-Tessera-Signature` | `sha256=` and the hex HMAC-SHA256 of `<timestamp>.<raw body>`, keyed with your secret |

`actor` is who did it (`user`, `agent`, `client`, `master` or `system`); `subject` is what it happened to. The body is a copy of the audit record. It never holds passwords, tokens or secrets.

## Verify every delivery

Anyone who knows your URL can post to it. Verify the signature before you trust a request.

1. Read the raw request body bytes. Do not parse and re-serialize the JSON.
2. Reject the request if `X-Tessera-Timestamp` is more than 5 minutes from your clock.
3. Compute `HMAC-SHA256(secret, timestamp + "." + raw_body)` as hex and compare it with the part of `X-Tessera-Signature` after `sha256=`, in constant time.

```ts
import { createHmac, timingSafeEqual } from "node:crypto";

export function verify(secret: string, headers: Headers, rawBody: string): boolean {
  const timestamp = headers.get("x-tessera-timestamp") ?? "";
  const signature = headers.get("x-tessera-signature") ?? "";
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
  const expected = "sha256=" + createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
  const a = Buffer.from(expected), b = Buffer.from(signature);
  return a.length === b.length && timingSafeEqual(a, b);
}
```

```python
import hashlib, hmac, time

def verify(secret: bytes, headers: dict, raw_body: bytes) -> bool:
    ts = headers["X-Tessera-Timestamp"]
    if abs(time.time() - int(ts)) > 300:
        return False
    expected = "sha256=" + hmac.new(secret, ts.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, headers["X-Tessera-Signature"])
```

Keep the `X-Tessera-Webhook-Id` values you have handled to refuse a replay (see below). The [helper libraries](/docs/connect/helpers.md) are planned, not published; the code above is all you need.

## Answer, retries and duplicates

Return a `2xx` quickly. Each attempt times out after 10 seconds, so queue slow work and acknowledge first.

| Your answer | What Tessera does |
| --- | --- |
| `2xx` | Marks it delivered |
| `5xx`, `408`, `429`, timeout, network error | Retries after about 1 minute, 10 minutes, 1 hour, 6 hours and 17 hours (each varied by up to 10 percent either way), 6 attempts in all over about a day, then gives up |
| Other `4xx` | Permanent failure, no retry |
| `3xx` | Permanent failure, no retry |

Deliveries can arrive more than once and out of order. Store each `X-Tessera-Webhook-Id` you have handled and skip repeats. Treat your copy of the data as a cache that you can repair from the admin API.

## Rotate a secret

There is no call that changes the secret of an existing subscription. To rotate:

1. Create a second subscription for the same URL and keep its new secret.
2. Make your receiver accept either secret.
3. Delete the old subscription.
4. Remove the old secret from your receiver.
