V2 / Security
Authentication
Configure bearer token headers, HMAC webhook signature verification, and environment-scoped keys in v2.
# Authentication (V2)
Configure bearer token headers, HMAC webhook signature verification, and environment-scoped keys in v2.
import Callout from '../../../components/Callout.astro';
All `v2` API requests authenticate using a bearer token in the `Authorization` header over HTTPS.
## Request Headers
| Header | Format | Purpose |
| --- | --- | --- |
| `Authorization` | `Bearer ax_live_...` | Authenticates the workspace key |
| `Content-Type` | `application/json` | Required on `POST`, `PUT`, and `PATCH` requests |
| `X-Request-Id` | `UUID v4` | Optional idempotency and trace correlation ID |
## Verifying Webhook Signatures
Every outbound webhook event includes an `X-Axis-Signature` header containing a hex-encoded HMAC-SHA256 digest computed over the raw request body:
```ts
import { createHmac, timingSafeEqual } from 'node:crypto';
export function verifyWebhookSignature(
rawBody: string,
signatureHex: string,
secret: string,
): boolean {
const expected = createHmac('sha256', secret).update(rawBody).digest('hex');
const a = Buffer.from(expected, 'utf8');
const b = Buffer.from(signatureHex, 'utf8');
return a.length === b.length && timingSafeEqual(a, b);
}
```
<Callout variant="tip" title="Timing-safe comparison">
Always compare raw signature buffers with `timingSafeEqual` (or Web Crypto constant-time comparison on Workers) after verifying equal byte length.
</Callout> All v2 API requests authenticate using a bearer token in the Authorization header over HTTPS.
Request Headers
| Header | Format | Purpose |
|---|---|---|
Authorization | Bearer ax_live_... | Authenticates the workspace key |
Content-Type | application/json | Required on POST, PUT, and PATCH requests |
X-Request-Id | UUID v4 | Optional idempotency and trace correlation ID |
Verifying Webhook Signatures
Every outbound webhook event includes an X-Axis-Signature header containing a hex-encoded HMAC-SHA256 digest computed over the raw request body:
import { createHmac, timingSafeEqual } from 'node:crypto';
export function verifyWebhookSignature(
rawBody: string,
signatureHex: string,
secret: string,
): boolean {
const expected = createHmac('sha256', secret).update(rawBody).digest('hex');
const a = Buffer.from(expected, 'utf8');
const b = Buffer.from(signatureHex, 'utf8');
return a.length === b.length && timingSafeEqual(a, b);
}