|
| 1 | +# Webhooks Admin UI |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The Webhooks Admin UI is the control center for managing webhook endpoints and event subscriptions in Numen. Accessible at `/admin/webhooks`, it provides a full CRUD interface for creating, editing, deleting webhook endpoints, managing event subscriptions, viewing delivery logs, and rotating signing secrets. |
| 6 | + |
| 7 | +## Access & Location |
| 8 | + |
| 9 | +- **URL:** `/admin/webhooks` |
| 10 | +- **Navigation:** Admin Panel → Settings → Webhooks |
| 11 | +- **Required Role:** Admin (or equivalent with webhook management permissions) |
| 12 | + |
| 13 | +## Features |
| 14 | + |
| 15 | +### Create Webhook Endpoints |
| 16 | + |
| 17 | +Create a new webhook endpoint by specifying: |
| 18 | +- **URL:** The HTTPS endpoint where webhook payloads will be delivered |
| 19 | +- **Event Subscriptions:** Select which event types trigger deliveries to this endpoint (e.g., `content.created`, `content.published`, etc.) |
| 20 | +- **Description:** Optional notes about the endpoint's purpose |
| 21 | + |
| 22 | +When you create an endpoint, Numen generates a **signing secret**. This secret is displayed only once — **copy it immediately and store it securely**. You cannot retrieve it later. Use this secret to verify webhook request signatures on your endpoint. |
| 23 | + |
| 24 | +### Manage Event Subscriptions |
| 25 | + |
| 26 | +For each endpoint, select which event types should trigger webhook deliveries. Common events include: |
| 27 | +- `content.created` |
| 28 | +- `content.published` |
| 29 | +- `content.updated` |
| 30 | +- `content.deleted` |
| 31 | +- `space.created` |
| 32 | +- And more |
| 33 | + |
| 34 | +You can add, remove, or modify subscriptions at any time without recreating the endpoint. |
| 35 | + |
| 36 | +### View Delivery Logs |
| 37 | + |
| 38 | +Monitor webhook delivery history per endpoint: |
| 39 | +- **Delivery Status:** Success (2xx) or failure with HTTP status code and error message |
| 40 | +- **Timestamp:** When the delivery was attempted |
| 41 | +- **Payload Size:** Request body size for debugging |
| 42 | +- **Response Time:** Latency in milliseconds |
| 43 | + |
| 44 | +Logs are retained for audit and troubleshooting. |
| 45 | + |
| 46 | +### Rotate Signing Secrets |
| 47 | + |
| 48 | +For security, rotate the endpoint's signing secret at any time: |
| 49 | + |
| 50 | +1. Click **Rotate Secret** on the endpoint detail view |
| 51 | +2. A new secret is generated and displayed **once only** |
| 52 | +3. **Copy the new secret immediately** — the old secret becomes invalid within seconds |
| 53 | +4. Update your webhook consumer to use the new secret |
| 54 | + |
| 55 | +This is useful if: |
| 56 | +- A secret is suspected to be compromised |
| 57 | +- You're changing your webhook consumer implementation |
| 58 | +- Regular security rotation is required by your compliance framework |
| 59 | + |
| 60 | +### Manual Redeliver |
| 61 | + |
| 62 | +If a webhook delivery failed or needs to be manually triggered, use the **Redeliver** action: |
| 63 | + |
| 64 | +- Select the delivery log entry you want to redeliver |
| 65 | +- Click **Redeliver** |
| 66 | +- The same payload is delivered again to the endpoint |
| 67 | + |
| 68 | +**Rate Limit:** Manual redeliveries are rate-limited to **10 per minute per user** to prevent accidental spam or abuse. |
| 69 | + |
| 70 | +## Signing Webhook Requests |
| 71 | + |
| 72 | +Numen signs all webhook payloads using HMAC-SHA256. Each request includes an `X-Numen-Signature` header with the format: |
| 73 | + |
| 74 | +``` |
| 75 | +X-Numen-Signature: v1=<signature> |
| 76 | +``` |
| 77 | + |
| 78 | +To verify a webhook: |
| 79 | + |
| 80 | +```php |
| 81 | +$secret = 'your_endpoint_secret'; |
| 82 | +$payload = file_get_contents('php://input'); |
| 83 | +$signature = hash_hmac('sha256', $payload, $secret); |
| 84 | +$expectedHeader = 'v1=' . $signature; |
| 85 | + |
| 86 | +if ($signature !== $_SERVER['HTTP_X_NUMEN_SIGNATURE'] ?? '') { |
| 87 | + http_response_code(403); |
| 88 | + die('Signature mismatch'); |
| 89 | +} |
| 90 | + |
| 91 | +// Process webhook |
| 92 | +``` |
| 93 | + |
| 94 | +## API Reference |
| 95 | + |
| 96 | +The webhooks admin UI is backed by REST endpoints under `/api/admin/webhooks`: |
| 97 | + |
| 98 | +- `GET /api/admin/webhooks` — List all endpoints |
| 99 | +- `POST /api/admin/webhooks` — Create endpoint |
| 100 | +- `GET /api/admin/webhooks/{id}` — Retrieve endpoint details |
| 101 | +- `PATCH /api/admin/webhooks/{id}` — Update endpoint and subscriptions |
| 102 | +- `DELETE /api/admin/webhooks/{id}` — Delete endpoint |
| 103 | +- `POST /api/admin/webhooks/{id}/rotate-secret` — Rotate signing secret |
| 104 | +- `GET /api/admin/webhooks/{id}/deliveries` — Paginated delivery log |
| 105 | +- `POST /api/admin/webhooks/{id}/deliveries/{deliveryId}/redeliver` — Manual redeliver (rate-limited) |
| 106 | + |
| 107 | +## Best Practices |
| 108 | + |
| 109 | +1. **Store Secrets Securely:** Always store your webhook signing secret in environment variables or a secure vault. Never commit it to version control. |
| 110 | + |
| 111 | +2. **Verify Signatures:** Always validate the `X-Numen-Signature` header on incoming webhooks to ensure requests came from Numen. |
| 112 | + |
| 113 | +3. **Handle Failures Gracefully:** Implement exponential backoff and retry logic on your webhook consumer in case of temporary network issues. |
| 114 | + |
| 115 | +4. **Use HTTPS Only:** Webhooks are delivered only to HTTPS endpoints for security. |
| 116 | + |
| 117 | +5. **Copy Secrets Immediately:** When you create or rotate a secret, copy it right away. You cannot retrieve it later. |
| 118 | + |
| 119 | +6. **Rotate Regularly:** Rotate secrets periodically (e.g., quarterly) as part of security best practices. |
| 120 | + |
| 121 | +7. **Monitor Delivery Logs:** Regularly check the delivery log for failed deliveries and investigate the cause. |
| 122 | + |
| 123 | +## Troubleshooting |
| 124 | + |
| 125 | +### "Signature mismatch" errors |
| 126 | + |
| 127 | +Ensure you're using the correct secret for the endpoint and that you're hashing the raw request body (not JSON-decoded data). |
| 128 | + |
| 129 | +### Webhook not delivering |
| 130 | + |
| 131 | +1. Verify the endpoint URL is correct and HTTPS |
| 132 | +2. Check that event subscriptions include the events you're listening for |
| 133 | +3. Review the delivery log for specific error messages |
| 134 | +4. Ensure your endpoint is responding with a 2xx status code within the timeout window (typically 10 seconds) |
| 135 | + |
| 136 | +### Secret is lost |
| 137 | + |
| 138 | +If you lose a secret before updating your webhook consumer, rotate it immediately. The old secret will become invalid, forcing you to re-configure. This is by design for security. |
| 139 | + |
0 commit comments