Title: BearerTokenAuthMiddleware × serve(transport="both") — needs A2A sibling + serve(auth=...) shortcut · Issue #558 · adcontextprotocol/adcp-client-python · GitHub
Open Graph Title: BearerTokenAuthMiddleware × serve(transport="both") — needs A2A sibling + serve(auth=...) shortcut · Issue #558 · adcontextprotocol/adcp-client-python
X Title: BearerTokenAuthMiddleware × serve(transport="both") — needs A2A sibling + serve(auth=...) shortcut · Issue #558 · adcontextprotocol/adcp-client-python
Description: What BearerTokenAuthMiddleware is documented MCP-only (src/adcp/server/auth.py:62-65): "A2A uses a different transport; wire a2a-sdk's ServerCallContext.user via a2a-sdk auth middleware on that side." But adopters wiring a unified seller...
Open Graph Description: What BearerTokenAuthMiddleware is documented MCP-only (src/adcp/server/auth.py:62-65): "A2A uses a different transport; wire a2a-sdk's ServerCallContext.user via a2a-sdk auth middleware on that sid...
X Description: What BearerTokenAuthMiddleware is documented MCP-only (src/adcp/server/auth.py:62-65): "A2A uses a different transport; wire a2a-sdk's ServerCallContext.user via a2a-sdk auth middleware on...
Opengraph URL: https://github.com/adcontextprotocol/adcp-client-python/issues/558
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"BearerTokenAuthMiddleware × serve(transport=\"both\") — needs A2A sibling + serve(auth=...) shortcut","articleBody":"## What\n\n`BearerTokenAuthMiddleware` is documented MCP-only ([`src/adcp/server/auth.py:62-65`](https://github.com/adcontextprotocol/adcp-client-python/blob/main/src/adcp/server/auth.py#L62-L65)):\n\n> \"A2A uses a different transport; wire a2a-sdk's `ServerCallContext.user` via a2a-sdk auth middleware on that side.\"\n\nBut adopters wiring a unified seller via `serve(transport=\"both\")` only get the one ASGI middleware list — there's no first-class way to wire matching auth on the A2A leg through the framework.\n\nConcrete blast: when `BearerTokenAuthMiddleware` is passed via `asgi_middleware=[...]` on `serve(transport=\"both\")`, it wraps the whole binary including A2A's public `/.well-known/agent-card.json` discovery endpoint, so unauthenticated discovery requests get rejected with 401, breaking A2A buyer auto-discovery entirely.\n\n## Repro (production-shape, not toy)\n\nsalesagent's [`core/main.py`](https://github.com/prebid/salesagent/blob/main/core/main.py): one binary serving MCP + A2A from the same handler/router, one Principal table, one token validates both transports. Buyer just picks a protocol. We hit the same gap.\n\n## Workaround we shipped (with a real security cost)\n\nWe wrote a 30-line [`ScopedAuthMiddleware`](https://github.com/prebid/salesagent/blob/main/core/middleware/scoped_auth.py) that runs `BearerTokenAuthMiddleware` only on `/mcp/*` paths. **A2A is currently unauthenticated in our build.** That's a regression we accepted because the framework didn't give us a clean way to wire auth on both legs simultaneously, and we needed `/.well-known/agent-card.json` reachable for discovery. Filing this so we can drop the workaround.\n\n## What we'd want\n\n**Option (b) from a chat with @bokelley:** add an `A2ABearerAuthMiddleware` sibling (validates the same token shape but populates `ServerCallContext.user` rather than reading an HTTP header inline) plus a `serve(auth=...)` shortcut that wires both legs with one config:\n\n```python\nserve(\n handler,\n transport=\"both\",\n auth=BearerTokenAuth(validate_token=_validate_token, header_name=\"x-adcp-auth\"),\n ...,\n)\n```\n\nInternally `serve` mounts `BearerTokenAuthMiddleware` on the MCP leg and `A2ABearerAuthMiddleware` on the A2A leg from the single `auth=` config. Adopters who need transport-specific auth keep the lower-level path (separate middlewares per leg).\n\nConsidered alternatives:\n- **(a) Make `BearerTokenAuthMiddleware` transport-aware** — awkward, A2A's auth model is different in shape (a2a-sdk reads `ServerCallContext.user` populated upstream, not an HTTP header re-validated on every request). A transport-aware mux either reimplements both auth styles or shells out to two underlying middlewares — at which point you've reinvented (b) inside a wrapper.\n- **(c) Fail-fast if BearerTokenAuthMiddleware is used as outer ASGI middleware on `transport=\"both\"`** — punts; doesn't actually solve the problem.\n\n## Filed by\n\nsalesagent kill-nginx/M2 spike — surfaced in [`core/SDK_FEEDBACK.md`](https://github.com/prebid/salesagent/blob/main/core/SDK_FEEDBACK.md) round 3.","author":{"url":"https://github.com/bokelley","@type":"Person","name":"bokelley"},"datePublished":"2026-05-04T09:58:58Z","url":"https://github.com/adcontextprotocol/adcp-client-python/issues/558"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3bf2da36-07a1-431c-feac-069f794ff464 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 803E:3D8CBB:C99803:10B6062:6B00F516 |
| html-safe-nonce | bfe16c2542ca0220a7592e1a6725a49ad4d6f2ea650ab2245d1fede3f3d9e443 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDNFOjNEOENCQjpDOTk4MDM6MTBCNjA2Mjo2QjAwRjUxNiIsInZpc2l0b3JfaWQiOiI3Mzg5NzU0ODAzODIxMjc4NDg2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 365704c5153f637b4a3699d9e1570d093acdcb5103860fe591639a9157996410 |
| hovercard-subject-tag | issue:4375598294 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/adcontextprotocol/adcp-client-python/558/issue_layout |
| twitter:image | https://opengraph.githubassets.com/951e9d7c24cb71a587932677ae8f81004f3109ff637b12c46facdd0aface8288/adcontextprotocol/adcp-client-python/issues/558 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/951e9d7c24cb71a587932677ae8f81004f3109ff637b12c46facdd0aface8288/adcontextprotocol/adcp-client-python/issues/558 |
| og:image:alt | What BearerTokenAuthMiddleware is documented MCP-only (src/adcp/server/auth.py:62-65): "A2A uses a different transport; wire a2a-sdk's ServerCallContext.user via a2a-sdk auth middleware on that sid... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bokelley |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/adcontextprotocol/adcp-client-python git https://github.com/adcontextprotocol/adcp-client-python.git |
| octolytics-dimension-user_id | 221690821 |
| octolytics-dimension-user_login | adcontextprotocol |
| octolytics-dimension-repository_id | 1090305973 |
| octolytics-dimension-repository_nwo | adcontextprotocol/adcp-client-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1090305973 |
| octolytics-dimension-repository_network_root_nwo | adcontextprotocol/adcp-client-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width