Repository navigation
feat(server): surface authenticator extra to BuyerAgentRegistry resolveByCredential - #1488
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1484
Summary
BuyerAgentRegistry.bearerOnlyand.mixed(shipped in 6.7.0, preview) receivedAdcpCredentialwhoseapi_keyvariant carries onlykey_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:
attachAuthInfo(serve.ts): Forwardprincipal.extrafrom theAuthPrincipalreturned byauthenticate()intoinfo.extraalongside claims and credential.credentialis always spread last to prevent an adopter-suppliedextra.credentialfrom overwriting the framework-enforced kind-discriminated credential (forgery vector closed by ordering).ResolveBuyerAgentByCredentialtype: Add optional second argextra?: Record<string, unknown>. TypeScript allows existing single-arg(credential) => ...implementations to satisfy the widened type — non-breaking.bearerOnly+mixedfactories: PassauthInfo.extraas the second arg toresolveByCredential.signingOnlyintentionally unchanged — signed path resolves bycredential.agent_urlonly.DX additions surfacing the previously-invisible forwarding chain:
extra?: Record<string, unknown>field onAuthPrincipalwith a full JSDoc example showing theverifyApiKey.verify → bearerOnlypattern.BuyerAgentResolveInput.extraJSDoc with reserved-key guidance (credential, standard JWT claim names).cached()decorator note:extrais not part of the cache key — two requests with the same credential but differentextrareturn the same cached result.What was tested
node --test test/lib/buyer-agent-registry.test.js— 27/27 pass (includes 5 newextra forwardingtests)node --test test/lib/buyer-agent-cache.test.js— 22/22 passnpx prettier --check— cleannpx tsc --project tsconfig.lib.json— pre-existing@types/node+moduleResolution=node10errors onmain(unrelated to this PR;tscstill emits output)server-buyer-agent-credential-synthesis.test.js(Stage 4 block) — test infra blocked by missingnode_modules/zodin local env; same failure onmainKnown limitation (noted in JSDoc)
BuyerAgentResolveInput.extrareceives the fullMCP AuthInfo.extrabag, which includes JWT claims (whenverifyBeareris used) and the SDK-internalcredentialkey 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
extrais absent fromresolveByAgentUrlargs, array check foradopterExtracovered bytypeof 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).AuthPrincipal.extranamed field + JSDoc example added. Main DX concern was discoverability from type hover — resolved.Session: https://claude.ai/code/session_01HCXvJwKtzwsGeVZ4kyVaBz
Generated by Claude Code