Skip to content

feat(server): surface authenticator extra to BuyerAgentRegistry resolveByCredential - #1488

Merged
bokelley merged 2 commits into
mainfrom
claude/issue-1484-beareronly-extra-forwarding
May 3, 2026
Merged

bokelley merged 2 commits into
mainfrom
claude/issue-1484-beareronly-extra-forwarding

Conversation

@bokelley

@bokelley bokelley commented May 3, 2026

Copy link
Copy Markdown
Contributor

Closes #1484

Summary

BuyerAgentRegistry.bearerOnly and .mixed (shipped in 6.7.0, preview) received AdcpCredential whose api_key variant carries only key_id: SHA-256(token) — never the raw bearer. This blocked adopters using prefix-based bearer conventions (demo tokens, tenant-encoded keys, Stripe-style test keys) that need the raw token to derive a commercial relationship without a per-token DB row.

This PR implements the three-part fix proposed in #1484:

  1. attachAuthInfo (serve.ts): Forward principal.extra from the AuthPrincipal returned by authenticate() into info.extra alongside claims and credential. credential is always spread last to prevent an adopter-supplied extra.credential from overwriting the framework-enforced kind-discriminated credential (forgery vector closed by ordering).

  2. ResolveBuyerAgentByCredential type: Add optional second arg extra?: Record<string, unknown>. TypeScript allows existing single-arg (credential) => ... implementations to satisfy the widened type — non-breaking.

  3. bearerOnly + mixed factories: Pass authInfo.extra as the second arg to resolveByCredential. signingOnly intentionally unchanged — signed path resolves by credential.agent_url only.

DX additions surfacing the previously-invisible forwarding chain:

  • Named extra?: Record<string, unknown> field on AuthPrincipal with a full JSDoc example showing the verifyApiKey.verify → bearerOnly pattern.
  • Expanded BuyerAgentResolveInput.extra JSDoc with reserved-key guidance (credential, standard JWT claim names).
  • cached() decorator note: extra is not part of the cache key — two requests with the same credential but different extra return the same cached result.

What was tested

  • node --test test/lib/buyer-agent-registry.test.js — 27/27 pass (includes 5 new extra forwarding tests)
  • node --test test/lib/buyer-agent-cache.test.js — 22/22 pass
  • npx prettier --check — clean
  • npx tsc --project tsconfig.lib.json — pre-existing @types/node + moduleResolution=node10 errors on main (unrelated to this PR; tsc still emits output)
  • Integration tests in server-buyer-agent-credential-synthesis.test.js (Stage 4 block) — test infra blocked by missing node_modules/zod in local env; same failure on main

Known limitation (noted in JSDoc)

BuyerAgentResolveInput.extra receives the full MCP AuthInfo.extra bag, which includes JWT claims (when verifyBearer is used) and the SDK-internal credential key alongside adopter-stamped fields. Adopters should not use reserved key names. A future PR could strip reserved keys before forwarding; deferred to avoid scope creep.

Pre-PR review

  • code-reviewer: Approved — non-breaking (TS structural typing confirmed), credential-last ordering closes forgery vector, test 4 logic fixed to validate extra is absent from resolveByAgentUrl args, array check for adopterExtra covered by typeof x === 'object' && !Array.isArray(x) guard. 1 nit: JWT reserved-key list in JSDoc is incomplete (noted in body above, full warning deferred to follow-up).
  • dx-expert: Approved after AuthPrincipal.extra named field + JSDoc example added. Main DX concern was discoverability from type hover — resolved.

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout <num> →
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

Session: https://claude.ai/code/session_01HCXvJwKtzwsGeVZ4kyVaBz


Generated by Claude Code

…veByCredential

Closes #1484

`BuyerAgentRegistry.bearerOnly` and `.mixed` now forward `authInfo.extra`
as a second optional arg to `resolveByCredential`, enabling prefix-based
bearer conventions (demo tokens, tenant-encoded keys) that rely on the raw
token rather than the SHA-256 hash in `key_id`.

Three-part change:
1. `attachAuthInfo` in serve.ts: forward `principal.extra` into `info.extra`
   alongside claims and credential. `credential` is always spread last to
   prevent adopter-supplied `extra.credential` from overwriting the
   framework-enforced kind-discriminated credential.
2. `ResolveBuyerAgentByCredential` type: add optional second arg
   `extra?: Record<string, unknown>`. Existing single-arg implementations
   continue to satisfy the widened type.
3. `bearerOnly` + `mixed` factories: pass `authInfo.extra` to resolver.
   `signingOnly` is intentionally unchanged (signed path uses agent_url only).

Also:
- Add named `extra` field with JSDoc to `AuthPrincipal` so adopters can
  discover the forwarding mechanism from type hover.
- Expand `BuyerAgentResolveInput.extra` JSDoc with reserved-key guidance.
- Add `cached()` decorator JSDoc note that `extra` is not part of cache key.
- Add 5 unit tests for extra forwarding in buyer-agent-registry.test.js.
- Add integration tests in server-buyer-agent-credential-synthesis.test.js.

https://claude.ai/code/session_01HCXvJwKtzwsGeVZ4kyVaBz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BuyerAgentRegistry bearerOnly: surface authenticator-stamped extra/principal to ResolveBuyerAgentByCredential

2 participants