Auth webhooks: user events signed with Standard Webhooks
How Ostiary tells your apps when users change: user and membership webhook events, Standard Webhooks signatures, retries, and a receiver to copy.
When users live in an identity provider, your applications still keep their own copy of some of that data: a profile row, a seat in a billing plan, a role in a workspace. Polling the identity provider to keep that copy fresh is slow and wasteful. Ostiary, the self-hosted identity provider built on Better Auth, sends webhooks instead: a signed HTTP request to your app each time a user or an organization membership changes. This post covers the events, the signature format, the delivery rules and a receiver you can copy.
Why an identity provider needs webhooks
OpenID Connect tells an app who someone is when they sign in. It says nothing about what happens between two sign-ins: an administrator bans an account, a person changes their email, a customer's Okta deactivates an employee through SCIM. Without a push from the identity provider, your app learns about it at the next sign-in at best, or never if the person stops coming back.
Webhooks close that gap. Typical uses:
- create the app's own user record as soon as someone signs up, before their first visit;
- revoke access or stop billing a seat when an account is banned, deactivated or deleted;
- keep names, emails and roles in sync with the source of truth;
- mirror organization memberships for a B2B app.
Setting up an endpoint
In the admin console, open Webhooks > Add an endpoint, enter an HTTPS URL and pick the events to send. The console shows the endpoint's signing secret once, when it is created; copy it then. Ostiary stores it encrypted with a key derived from BETTER_AUTH_SECRET, so a database dump alone does not reveal it. Send test event sends a webhook.test to check the wiring.
The events
| Event | Sent when |
|---|---|
user.created | an account is created |
user.updated | the name, email, email verification, username or picture changes |
user.deleted | an account is deleted |
user.banned, user.unbanned | an account is banned or unbanned, including SCIM deactivation and reactivation |
user.role_changed | the account's role changes |
organization.member.added, organization.member.removed, organization.member.role_changed | an organization membership changes |
Ban events caused by SCIM carry "source": "scim", so your app can tell an administrator's decision from a customer's directory. The SAML SSO and organizations post explains where SCIM fits in a B2B setup.
The payload
Each delivery is a POST with a JSON body. Here is a role change:
{
"id": "evt_570736d750ed4c4596883d04c30e23d1",
"type": "user.role_changed",
"timestamp": "2026-10-08T15:52:24.067Z",
"data": {
"user": { "id": "iMRp...", "email": "bob@example.com", "emailVerified": true, "name": "Bob", "username": "bob", "image": null, "role": "admin", "banned": false },
"previousRole": "user"
}
}
Payloads are deliberately small: ids, email, name, role and organization. They never contain passwords, tokens, two-factor secrets or ban reasons. In the code, each snapshot function lists the fields it copies, so a new database column does not end up in webhooks by accident. Membership events carry data.member with id, organizationId, userId and role.
Standard Webhooks signatures
Anyone can send a POST to a public URL, so a receiver must check that a request really comes from Ostiary. Ostiary signs every delivery following Standard Webhooks, a community specification for sending webhooks securely and reliably. Each request has three headers:
webhook-id: the event id. It stays the same on every retry, so use it to ignore duplicates.webhook-timestamp: when this attempt was sent, in seconds.webhook-signature: one or more signatures, separated by spaces, each writtenv1,<base64>.
A v1 signature is an HMAC with SHA-256 of the string <id>.<timestamp>.<body>. The key is the bytes encoded in the secret after its whsec_ prefix. Signing the id and the timestamp along with the body means an attacker cannot replay an old delivery with a new timestamp, nor change the id to slip past your duplicate check.
Verify before you parse
Compute the signature over the raw body, exactly as it arrived. Parsing the JSON and serializing it again can change spacing or key order, and the signature will no longer match. Compare signatures in constant time, and reject timestamps too far from your clock. This function, from Ostiary's webhook guide, does all three with Node's crypto module:
import { createHmac, timingSafeEqual } from "node:crypto";
// secret: "whsec_..." from the admin console. body: the raw request body (a string).
function verifyOstiaryWebhook(secret, headers, body) {
const id = headers["webhook-id"];
const timestamp = headers["webhook-timestamp"];
const signatures = headers["webhook-signature"] ?? "";
if (!id || !timestamp || Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
const key = Buffer.from(secret.slice("whsec_".length), "base64");
const expected = Buffer.from(`v1,${createHmac("sha256", key).update(`${id}.${timestamp}.${body}`).digest("base64")}`);
return signatures.split(" ").some((s) => s.length === expected.length && timingSafeEqual(Buffer.from(s), expected));
}
The five-minute window (300 seconds) bounds how long a captured request could be replayed. timingSafeEqual avoids leaking, through response times, how much of a forged signature was right. Any Standard Webhooks library works too, such as the standardwebhooks package on npm.
A receiver
In a route handler that receives a Web Request, read the body as text, verify it, and only then parse it:
export async function POST(request: Request) {
const body = await request.text();
const headers = Object.fromEntries(request.headers);
if (!verifyOstiaryWebhook(process.env.OSTIARY_WEBHOOK_SECRET, headers, body)) {
return new Response("Invalid signature", { status: 401 });
}
const event = JSON.parse(body);
// Skip events already handled: request.headers.get("webhook-id") is the same on every retry.
// Then act on event.type: "user.created", "user.banned", ...
return new Response(null, { status: 204 });
}
Answer quickly. If the work takes long, store the event, answer 2xx, and process it in the background.
Rotating the secret
Regenerate secret creates a new secret and shows it once. For the next 24 hours, Ostiary signs each delivery with both the old and the new secret, which is why webhook-signature is a list. Deploy the new secret to your receiver during that window and no delivery fails. If you change BETTER_AUTH_SECRET, the stored webhook secrets can no longer be decrypted: regenerate each endpoint's secret afterwards.
Delivery, retries and the delivery log
Ostiary records the event once the change is committed and sends it right after the request that caused it, without slowing that request down: a slow receiver never delays a sign-up. Your endpoint must answer with any 2xx within 10 seconds. Redirects are not followed.
A failed delivery is retried 4 times, after 5 minutes, 1 hour, 6 hours and 18 hours, then marked failed. An endpoint that fails 15 times in a row is disabled, and the console shows it. Each endpoint has a Delivery log with the status, the response code, the number of attempts, the next retry and the start of the answer, plus a Redeliver button. Endpoint changes appear in the audit log.
Retries on Vercel
Retries are sent by GET /api/cron/webhooks on the auth app, protected by CRON_SECRET (16 characters or more); Vercel Cron sends it as Authorization: Bearer $CRON_SECRET. Ostiary's vercel.json runs that route once a day, because Vercel's Hobby plan only allows cron jobs that run once per day. On Pro, set the schedule to */5 * * * *, or call the route from any other scheduler with the same header. Instances also retry due deliveries on their own, at most once a minute, whenever they send an event. The deployment guide lists CRON_SECRET with the other environment variables.
Guards on the sending side
A webhook URL is a request your server makes to an address someone typed, which is a classic path to server-side request forgery. Ostiary only accepts HTTPS URLs that resolve to public addresses. Private, loopback, link-local and cloud metadata addresses are refused when the endpoint is saved and again before each delivery, and the connection is pinned to the addresses that were checked, so a DNS change between the check and the request cannot redirect it. For local development, WEBHOOKS_ALLOW_LOCALHOST=true also accepts http://localhost; it is ignored in production.
Webhooks also respect account deletion. When an account is deleted, the payloads of deliveries already sent, kept 30 days for the delivery log, are redacted. Pending deliveries, including the user.deleted event itself, still go out, so your app hears about the deletion and can erase its own copy.
Try it
Webhooks come with every Ostiary instance, next to single sign-on over OIDC and SAML. Deploy your own, add an endpoint, and press Send test event. To see everything else included, read Ostiary as a self-hosted, open-source Auth0 alternative.