From 9912e2ef5cc9d5bd0f7b43fb884cd82b09601314 Mon Sep 17 00:00:00 2001 From: Shivam Sharma <192242476+ShivamSharma43@users.noreply.github.com> Date: Sun, 8 Nov 2026 00:46:27 +0530 Subject: [PATCH 1/2] fix(compat): serve v0.3 gRPC agent cards with a device code OAuth flow A v1.0 OAuth2 scheme whose flow is device_code, which v0.3 does not have, converts to a v0.3 OAuthFlows with no flow set. ToProto.oauth2_flows raised ValueError for that, so the v0.3 gRPC GetAgentCard failed with UNKNOWN for any card carrying such a scheme. The v0.3 JSON-RPC and REST bindings already serve the same scheme with empty flows. Return an empty OAuthFlows instead of raising. FromProto.oauth2_flows also read an OAuthFlows with no flow set as a password flow with empty URLs; it now returns an empty OAuthFlows as well. Co-Authored-By: Claude Opus 5.5 --- src/a2a/compat/v0_3/proto_utils.py | 20 +++++++------ tests/compat/v0_3/test_grpc_handler.py | 39 ++++++++++++++++++++++++++ tests/compat/v0_3/test_proto_utils.py | 10 +++++-- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/a2a/compat/v0_3/proto_utils.py b/src/a2a/compat/v0_3/proto_utils.py index d7ac19085..0ad90292f 100644 --- a/src/a2a/compat/v0_3/proto_utils.py +++ b/src/a2a/compat/v0_3/proto_utils.py @@ -572,7 +572,9 @@ def oauth2_flows(cls, flows: types.OAuthFlows) -> a2a_pb2.OAuthFlows: token_url=flows.password.token_url, ), ) - raise ValueError('Unknown oauth flow definition') + # No v0.3 flow is set, e.g. for a v1.0 device code flow, which v0.3 + # does not have. + return a2a_pb2.OAuthFlows() @classmethod def skill(cls, skill: types.AgentSkill) -> a2a_pb2.AgentSkill: @@ -1056,13 +1058,15 @@ def oauth2_flows(cls, flows: a2a_pb2.OAuthFlows) -> types.OAuthFlows: scopes=dict(flows.implicit.scopes.items()), ), ) - return types.OAuthFlows( - password=types.PasswordOAuthFlow( - refresh_url=flows.password.refresh_url, - scopes=dict(flows.password.scopes.items()), - token_url=flows.password.token_url, - ), - ) + if flows.HasField('password'): + return types.OAuthFlows( + password=types.PasswordOAuthFlow( + refresh_url=flows.password.refresh_url, + scopes=dict(flows.password.scopes.items()), + token_url=flows.password.token_url, + ), + ) + return types.OAuthFlows() @classmethod def stream_response( diff --git a/tests/compat/v0_3/test_grpc_handler.py b/tests/compat/v0_3/test_grpc_handler.py index 3c4572923..813f15242 100644 --- a/tests/compat/v0_3/test_grpc_handler.py +++ b/tests/compat/v0_3/test_grpc_handler.py @@ -496,3 +496,42 @@ async def test_extract_task_and_config_id_invalid( ): with pytest.raises(InvalidParamsError): handler._extract_task_and_config_id('invalid-name') + + +@pytest.mark.asyncio +async def test_get_agent_card_with_device_code_oauth_flow( + handler: compat_grpc_handler.CompatGrpcHandler, + mock_request_handler: AsyncMock, + mock_grpc_context: AsyncMock, + sample_agent_card: a2a_pb2.AgentCard, +) -> None: + """A v1.0 device code flow, which v0.3 lacks, is sent with no flows.""" + sample_agent_card.security_schemes['device'].CopyFrom( + a2a_pb2.SecurityScheme( + oauth2_security_scheme=a2a_pb2.OAuth2SecurityScheme( + description='Device code', + flows=a2a_pb2.OAuthFlows( + device_code=a2a_pb2.DeviceCodeOAuthFlow( + device_authorization_url='https://auth.example.com/device', + token_url='https://auth.example.com/token', + scopes={'read': 'Read access'}, + ) + ), + ) + ) + ) + mock_request_handler.on_get_extended_agent_card.return_value = ( + sample_agent_card + ) + + response = await handler.GetAgentCard( + a2a_v0_3_pb2.GetAgentCardRequest(), mock_grpc_context + ) + + mock_grpc_context.abort.assert_not_called() + assert response.security_schemes['device'] == a2a_v0_3_pb2.SecurityScheme( + oauth2_security_scheme=a2a_v0_3_pb2.OAuth2SecurityScheme( + description='Device code', + flows=a2a_v0_3_pb2.OAuthFlows(), + ) + ) diff --git a/tests/compat/v0_3/test_proto_utils.py b/tests/compat/v0_3/test_proto_utils.py index 9a037f77b..de14b4b1b 100644 --- a/tests/compat/v0_3/test_proto_utils.py +++ b/tests/compat/v0_3/test_proto_utils.py @@ -234,9 +234,13 @@ def test_oauth_flows_conversion(self): proto_auth_code_flow = proto_utils.ToProto.oauth2_flows(auth_code_flow) assert proto_auth_code_flow.HasField('authorization_code') - # Test invalid flow - with pytest.raises(ValueError): - proto_utils.ToProto.oauth2_flows(types.OAuthFlows()) + # Test no flow, e.g. a v1.0 device code flow converted to v0.3 + proto_no_flow = proto_utils.ToProto.oauth2_flows(types.OAuthFlows()) + assert proto_no_flow == a2a_pb2.OAuthFlows() + assert ( + proto_utils.FromProto.oauth2_flows(proto_no_flow) + == types.OAuthFlows() + ) # Test FromProto roundtrip_password = proto_utils.FromProto.oauth2_flows( From 6905db07b004884ea02202d19bbf9a3f5736caf6 Mon Sep 17 00:00:00 2001 From: Shivam Sharma <192242476+ShivamSharma43@users.noreply.github.com> Date: Fri, 13 Nov 2026 12:01:43 +0530 Subject: [PATCH 2/2] test(compat): serve a device code OAuth scheme in the cross-version 1.0 server card The 1.0 server's card now has an OAuth2 scheme with only a device code flow and advertises the extended card, so the v0.3 SDK client fetches the card from the server over gRPC, JSON-RPC and REST and must accept the empty v0.3 flows. Co-Authored-By: Claude Opus 5.5 --- .../cross_version/client_server/client_0_3.py | 15 ++++++++++- .../cross_version/client_server/client_1_0.py | 4 ++- .../cross_version/client_server/server_1_0.py | 26 ++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/tests/integration/cross_version/client_server/client_0_3.py b/tests/integration/cross_version/client_server/client_0_3.py index 70a3263bd..8a4f43d72 100644 --- a/tests/integration/cross_version/client_server/client_0_3.py +++ b/tests/integration/cross_version/client_server/client_0_3.py @@ -15,6 +15,7 @@ FileWithBytes, FileWithUri, Message, + OAuth2SecurityScheme, Part, Role, TaskIdParams, @@ -224,7 +225,19 @@ async def test_get_extended_agent_card(client): print( f'card.supports_authenticated_extended_card is: {card.supports_authenticated_extended_card}' ) - assert card.supports_authenticated_extended_card in (False, None) + assert card.supports_authenticated_extended_card is True + + scheme = card.security_schemes['oauth'].root + assert isinstance(scheme, OAuth2SecurityScheme) + assert scheme.description == 'Device code' + # v0.3 has no device code flow, so the server sends no flows. The + # v0.3 gRPC client reads empty flows as a password flow with empty + # fields. + flows = scheme.flows + assert flows.authorization_code is None + assert flows.client_credentials is None + assert flows.implicit is None + assert flows.password is None or flows.password.token_url == '' print(f'Success: get_extended_agent_card passed.') diff --git a/tests/integration/cross_version/client_server/client_1_0.py b/tests/integration/cross_version/client_server/client_1_0.py index 6e463854b..bdb868a00 100644 --- a/tests/integration/cross_version/client_server/client_1_0.py +++ b/tests/integration/cross_version/client_server/client_1_0.py @@ -212,7 +212,9 @@ async def test_get_extended_agent_card(client): if card.name == 'Server 1.0': assert len(card.supported_interfaces) == 4 - assert card.capabilities.extended_agent_card in (False, None) + assert card.capabilities.extended_agent_card is True + flows = card.security_schemes['oauth'].oauth2_security_scheme.flows + assert flows.device_code.token_url == 'https://auth.example.com/token' else: assert len(card.supported_interfaces) > 0 assert card.capabilities.extended_agent_card in (False, None) diff --git a/tests/integration/cross_version/client_server/server_1_0.py b/tests/integration/cross_version/client_server/server_1_0.py index 76ae35be0..152d1eb52 100644 --- a/tests/integration/cross_version/client_server/server_1_0.py +++ b/tests/integration/cross_version/client_server/server_1_0.py @@ -23,7 +23,11 @@ AgentCapabilities, AgentCard, AgentInterface, + DeviceCodeOAuthFlow, + OAuth2SecurityScheme, + OAuthFlows, Part, + SecurityScheme, TaskState, ) from a2a.utils import TransportProtocol @@ -138,7 +142,27 @@ async def main_async(http_port: int, grpc_port: int): description='Server running on a2a v1.0', version='1.0.0', skills=[], - capabilities=AgentCapabilities(streaming=True, push_notifications=True), + capabilities=AgentCapabilities( + streaming=True, + push_notifications=True, + # Makes v0.3 clients fetch the extended card from the server. + extended_agent_card=True, + ), + # v0.3 has no device code flow, so v0.3 clients get no flows. + security_schemes={ + 'oauth': SecurityScheme( + oauth2_security_scheme=OAuth2SecurityScheme( + description='Device code', + flows=OAuthFlows( + device_code=DeviceCodeOAuthFlow( + device_authorization_url='https://auth.example.com/device', + token_url='https://auth.example.com/token', + scopes={'read': 'Read access'}, + ) + ), + ) + ) + }, default_input_modes=['text/plain'], default_output_modes=['text/plain'], supported_interfaces=[