Overview

Authentication is configured when a webhook is created or edited. See the Webhooks overview for delivery headers and the request body structure.

Three modes are available: none, token, and hmac. HMAC is recommended.


None

No additional credentials are configured. Deliveries include only the standard ASX Energy headers:

  • Content-Type
  • User-Agent
  • X-Webhook-Timestamp
  • X-Webhook-Event-Id

Use this mode only when the endpoint is otherwise protected (for example, network allowlisting).


Token

A custom HTTP header name and secret value are configured. On every POST, that header is set to the configured value.

Setting Description
Header name Name of the request header to set
Secret Value sent in that header on each delivery

A dedicated custom header (for example X-API-Key) is recommended because it reduces the risk of interference from clients, browsers, or intermediaries.

The following header names are reserved and cannot be used:

  • X-Webhook-Timestamp
  • X-Webhook-Event-Id
  • X-Webhook-Signature
  • Host
  • User-Agent
  • Cookie
  • Accept
  • Content-Type
  • Content-Length

Validate the header value on your endpoint before processing the payload.


HMAC

A shared secret is configured. Each delivery includes an X-Webhook-Signature header containing an HMAC-SHA256 digest of the request, encoded as lowercase hexadecimal.

This mode is recommended because the signature binds the body, event id, and timestamp, and does not require sending the secret on every request.

Verifying signatures

  1. Read the raw request body. Do not re-serialize a parsed JSON object.
  2. Construct the signed string: {X-Webhook-Timestamp}.{X-Webhook-Event-Id}.{rawBody}.
  3. Compute HMAC-SHA256 using the shared secret and encode the digest as lowercase hexadecimal.
  4. Compare the result to X-Webhook-Signature using a constant-time comparison.
  5. Reject the request if the timestamp falls outside an acceptable skew (for example, 60 seconds).

Python example:

import hashlib
import hmac
import json
import time


def verify_webhook(headers: dict, raw_body: bytes | str, secret: str) -> dict:
    timestamp = headers["x-webhook-timestamp"]
    event_id = headers["x-webhook-event-id"]
    signature = headers["x-webhook-signature"]
    body = raw_body if isinstance(raw_body, str) else raw_body.decode("utf-8")

    expected = hmac.new(
        secret.encode("utf-8"),
        f"{timestamp}.{event_id}.{body}".encode("utf-8"),
        hashlib.sha256,
    ).hexdigest()

    if not hmac.compare_digest(signature, expected):
        raise ValueError("Invalid signature")

    if abs(time.time() * 1000 - int(timestamp)) > 60_000:
        raise ValueError("Stale timestamp")

    return json.loads(body)

On retry, the same event id and payload data are reused. A new timestamp and signature are generated.