feat(auth): per-leg header config + agent-card bearerAuth scheme#595
Merged
feat(auth): per-leg header config + agent-card bearerAuth scheme#595
Conversation
Add per-leg header knobs to BearerTokenAuth and auto-publish a matching security scheme on the A2A agent card so a2a-sdk's client interceptor attaches credentials without seller-side intervention. Defaults preserve pre-#57 single-knob behavior (Authorization + Bearer prefix on both legs — RFC 6750, the protocol-canonical carrier). The mcp_/a2a_ knobs are an opt-in escape hatch for adopters with legacy clients that send a raw token in a custom header (e.g. x-adcp-auth); the spec is moving toward Authorization: Bearer canonical for both transports. Closes salesagent#57 items 1 and 2; item 3 is a separate spec-repo PR. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Closes upstream items 1 and 2 from salesagent#57. With these in place, the
BearerToAdcpAuthMiddlewareshim in salesagent PR #60 becomes deletable.BearerTokenAuth—mcp_header_name/a2a_header_name/mcp_bearer_prefix_required/a2a_bearer_prefix_required. One config drives both legs without a translation middleware. Setting both legacyheader_nameand a per-leg knob raisesValueErrorat construction.BearerTokenAuthis configured,_build_agent_cardemits a matchingsecuritySchemes+securityRequirementsso a2a-sdk's client auth interceptor attaches credentials instead of short-circuiting against an empty envelope. Bearer-prefix configs publishHTTPAuthSecurityScheme(scheme="bearer")under idbearerAuth; raw-token custom-header configs publishAPIKeySecuritySchemeunder idadcpAuth.Defaults & back-compat
Authorization: Bearer <token>(RFC 6750) is the protocol-canonical carrier on both legs. It's the only header backed by an actual RFC, what every off-the-shelf MCP / A2A / HTTP client emits by default, and what the AdCP spec is moving toward as canonical for both transports.x-adcp-authis an opt-in legacy-compat alias, not a default — for adopters with deployed MCP clients that send a raw token in a custom header and can't be updated. Reach for it via:Defaults preserve pre-#57 single-knob behavior — existing
BearerTokenAuth(validate_token=...)adopters keep working unchanged.Construction guards (
__post_init__)Authorization+bearer_prefix_required=Falserejected — RFC 7235 reservesAuthorizationfor<scheme> <credentials>. Raw-token schemes need a custom header name.Out of scope
Authorization: Bearercanonical withx-adcp-authas a documented compat alias) is a separate spec-repo PR.Test plan
ruff check src/cleanmypy src/adcp/clean (783 source files)pytest tests/ -v— 4165 passed (+8 new tests vs prior run)tests/test_auth_per_leg_headers.py— 22 tests covering: resolved-default precedence, legacy single-knob back-compat, per-leg overrides, conflict guards, empty-header rejection, RFC 7235 misuse rejection, A2A middleware honors per-leg config, A2A header-name case-insensitive match, agent-card scheme variants (bearerAuthHTTP /adcpAuthAPI-key), end-to-end MCP per-leg routing throughBearerTokenAuthMiddleware, end-to-end agent-card route serializationbearer_format, empty-header rejection, missing E2E + case-sensitivity tests)🤖 Generated with Claude Code