Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,29 @@ the delivery mode and credential fingerprint into its signed body without
sending the credential. Custom egress clients, proxies, and mTLS transports are
for normal delivery paths, not registration challenges.

Passing `seller_agent_url` and `event_types` produces the AdCP 3.2 challenge.
Calls written for adcp 9.6 that omit both still work on 9.x but emit a
`DeprecationWarning`, and adcp 10.0 makes both arguments required:

- `challenge_webhook_destination(...)` sends the old four-field challenge. With
`sender=` it is RFC 9421-signed. With only `authentication=`, it is sent with
legacy Bearer or HMAC-SHA256 headers instead, and a second warning says that
10.0 also requires an RFC 9421 `sender=`.
- `WebhookSender.send_webhook_challenge(...)` sends the old four-field challenge
with the sender's own authentication. On a sender that doesn't sign with RFC
9421 (Bearer, HMAC-SHA256 or Standard Webhooks), that is its non-RFC 9421
authentication, and a second warning says 10.0 requires an RFC 9421 sender.
- `create_webhook_challenge_payload(...)` returns the old four-field payload. It
only builds the payload; it doesn't send or sign anything.

Passing the new arguments opts into the whole 3.2 contract, RFC 9421 signing
included: `challenge_webhook_destination` then requires an RFC 9421 `sender=`,
and `send_webhook_challenge` rejects a sender that doesn't sign with RFC 9421.
Omitting only one of the two raises `TypeError`, as a missing required argument
does.
`send_webhook_challenge` and `create_webhook_challenge_payload` accept
`authentication=` only together with the new arguments.

Wholesale feed notifications use stable types from `adcp` / `adcp.types`:

```python
Expand Down
23 changes: 23 additions & 0 deletions docs/handler-authoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,29 @@ except WebhookChallengeError as exc:
return {"errors": [exc.to_error()]}
```

Passing `seller_agent_url` and `event_types` produces the AdCP 3.2 challenge.
Calls written for adcp 9.6 that omit both still work on 9.x but emit a
`DeprecationWarning`, and adcp 10.0 makes both arguments required:

- `challenge_webhook_destination(...)` sends the old four-field challenge. With
`sender=` it is RFC 9421-signed. With only `authentication=`, it is sent with
legacy Bearer or HMAC-SHA256 headers instead, and a second warning says that
10.0 also requires an RFC 9421 `sender=`.
- `WebhookSender.send_webhook_challenge(...)` sends the old four-field challenge
with the sender's own authentication. On a sender that doesn't sign with RFC
9421 (Bearer, HMAC-SHA256 or Standard Webhooks), that is its non-RFC 9421
authentication, and a second warning says 10.0 requires an RFC 9421 sender.
- `create_webhook_challenge_payload(...)` returns the old four-field payload. It
only builds the payload; it doesn't send or sign anything.

Passing the new arguments opts into the whole 3.2 contract, RFC 9421 signing
included: `challenge_webhook_destination` then requires an RFC 9421 `sender=`,
and `send_webhook_challenge` rejects a sender that doesn't sign with RFC 9421.
Omitting only one of the two raises `TypeError`, as a missing required argument
does.
`send_webhook_challenge` and `create_webhook_challenge_payload` accept
`authentication=` only together with the new arguments.

If you only need to preflight a URL before deciding whether the subscription
changed, use `validate_webhook_destination_url` directly:

Expand Down
14 changes: 14 additions & 0 deletions src/adcp/_unset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Sentinel default for arguments whose omission selects a deprecated call shape.

Unlike ``None``, the sentinel tells "not passed" apart from "passed as None", so
an explicit ``None`` keeps failing the way the current API does instead of
quietly selecting a deprecated path. It lives in its own module so that
``adcp.webhooks`` and ``adcp.webhook_sender`` share one object without an
import cycle.
"""

from __future__ import annotations

from typing import Any

UNSET: Any = object()
90 changes: 86 additions & 4 deletions src/adcp/webhook_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from pydantic import BaseModel, TypeAdapter

from adcp._deferred_adapters import deferred_adapter
from adcp._unset import UNSET as _UNSET
from adcp.signing.constants import WEBHOOK_ACCEPTED_ADCP_USES
from adcp.signing.crypto import (
ALG_ED25519,
Expand Down Expand Up @@ -1640,8 +1641,8 @@ async def send_webhook_challenge(
url: str,
account_id: str,
subscriber_id: str,
seller_agent_url: str,
event_types: Sequence[str],
seller_agent_url: str = _UNSET,
event_types: Sequence[str] = _UNSET,
authentication: AdCPBaseModel | Mapping[str, Any] | None = None,
challenge: str | None = None,
extra_headers: Mapping[str, str] | None = None,
Expand All @@ -1657,12 +1658,36 @@ async def send_webhook_challenge(
Pair this low-level sender method with
:func:`adcp.webhooks.challenge_webhook_destination` when you also
want URL validation and response echo checking in one call.

Passing ``seller_agent_url`` and ``event_types`` sends the AdCP 3.2
challenge and requires an RFC 9421 sender. Omitting both is
deprecated: it emits a :class:`DeprecationWarning` and sends the
four-field adcp 9.6 challenge with this sender's own authentication.
On a sender that does not sign with RFC 9421 (Bearer, HMAC-SHA256 or
Standard Webhooks) that means its non-RFC 9421 authentication, with a
second :class:`DeprecationWarning`. adcp 10.0 requires both arguments
and an RFC 9421 sender.
"""

_check_challenge_fields_passed_together(
"WebhookSender.send_webhook_challenge",
seller_agent_url=seller_agent_url,
event_types=event_types,
)
if seller_agent_url is _UNSET:
return await self._send_v9_6_webhook_challenge(
url=url,
account_id=account_id,
subscriber_id=subscriber_id,
authentication=authentication,
challenge=challenge,
extra_headers=extra_headers,
)

if not self.signs_with_rfc9421:
raise ValueError("webhook challenges require RFC 9421 signing")

payload = create_webhook_challenge_payload(
payload = _build_webhook_challenge_payload(
account_id=account_id,
subscriber_id=subscriber_id,
seller_agent_url=seller_agent_url,
Expand All @@ -1679,6 +1704,56 @@ async def send_webhook_challenge(
extra_headers=extra_headers,
)

async def _send_v9_6_webhook_challenge(
self,
*,
url: str,
account_id: str,
subscriber_id: str,
authentication: AdCPBaseModel | Mapping[str, Any] | None,
challenge: str | None,
extra_headers: Mapping[str, str] | None,
) -> WebhookDeliveryResult:
"""adcp 9.6 ``send_webhook_challenge`` behaviour, kept for 9.x callers.

Reached only when the caller omits ``seller_agent_url`` and
``event_types``. Remove in 10.0, when those arguments become required.
"""

if authentication is not None:
raise TypeError(
"WebhookSender.send_webhook_challenge() binds authentication only into "
"the AdCP 3.2 challenge; pass seller_agent_url and event_types too"
)
# Frames: warn helper -> this method -> send_webhook_challenge -> caller.
_warn_missing_challenge_fields("WebhookSender.send_webhook_challenge", stacklevel=4)
if not self.signs_with_rfc9421:
# Frames: warnings.warn -> this method -> send_webhook_challenge -> caller.
warnings.warn(
"WebhookSender.send_webhook_challenge() called on a sender that does "
"not sign with RFC 9421; sending the proof-of-control challenge with "
"this sender's non-RFC 9421 authentication. adcp 10.0 "
"requires an RFC 9421 sender: construct it with "
"WebhookSender.from_jwk(...) and pass the durable config's legacy "
"credentials as authentication=, together with seller_agent_url and "
"event_types.",
DeprecationWarning,
stacklevel=3,
)
payload = _legacy_webhook_challenge_payload(
account_id=account_id,
subscriber_id=subscriber_id,
challenge=challenge,
)
challenge_value = str(payload["challenge"])
body = json.dumps(payload, separators=(",", ":")).encode("utf-8")
return await self._send_bytes(
url=url,
body=body,
idempotency_key=challenge_value,
extra_headers=extra_headers,
)

async def send_raw(
self,
*,
Expand Down Expand Up @@ -1883,12 +1958,19 @@ async def _send_bytes(
# bottom (after the classes are defined) to break the webhooks <-> webhook_sender
# cycle — see the note next to the removed top-level import.
from adcp.webhooks import ( # noqa: E402
_build_webhook_challenge_payload,
_check_challenge_fields_passed_together,
_legacy_webhook_challenge_payload,
_warn_missing_challenge_fields,
create_mcp_webhook_payload,
create_media_buy_delivery_webhook_payload,
create_webhook_challenge_payload,
generate_webhook_idempotency_key,
to_wire_dict,
)
from adcp.webhooks import (
# Unused here since the 3.2 split; kept importable from this module as in adcp 9.6.
create_webhook_challenge_payload as create_webhook_challenge_payload,
)
Comment thread
bokelley marked this conversation as resolved.
Resolved

__all__ = [
"DockerLocalhostRewrite",
Expand Down
Loading
Loading