Repository navigation
Commit 2ccef0d
fix(compat): serve v0.3 gRPC agent cards with a device code OAuth flow (a2aproject#1434)
# Description
The v0.3 gRPC `GetAgentCard` fails for an agent card that has an OAuth2
scheme with a device code flow.
v1.0 added `DeviceCodeOAuthFlow`, and v0.3 has no equivalent, so
`to_compat_oauth_flows` leaves the v0.3 `OAuthFlows` with no flow set.
`ToProto.oauth2_flows` raises `ValueError('Unknown oauth flow
definition')` for that. `CompatGrpcHandler._handle_unary` only catches
`A2AError`, so the call fails with `UNKNOWN`:
```python
from a2a.compat.v0_3.conversions import to_compat_agent_card
from a2a.compat.v0_3.proto_utils import ToProto
from a2a.types.a2a_pb2 import (
AgentCard, AgentInterface, DeviceCodeOAuthFlow, OAuth2SecurityScheme,
OAuthFlows, SecurityScheme,
)
card = AgentCard(
name='a', description='d', version='1',
supported_interfaces=[AgentInterface(
url='http://x', protocol_binding='GRPC', protocol_version='0.3')],
security_schemes={'device': SecurityScheme(
oauth2_security_scheme=OAuth2SecurityScheme(flows=OAuthFlows(
device_code=DeviceCodeOAuthFlow(
device_authorization_url='https://a/device',
token_url='https://a/token'))))},
)
ToProto.agent_card(to_compat_agent_card(card))
# ValueError: Unknown oauth flow definition
```
The v0.3 JSON-RPC and REST bindings serve the same scheme as `"flows":
{}`, and the public agent card does too.
## Fix
- `ToProto.oauth2_flows` returns an empty `OAuthFlows` when no flow is
set, instead of raising. gRPC clients then get the same scheme the JSON
bindings already send.
- `FromProto.oauth2_flows` returned a password flow with empty URLs for
an `OAuthFlows` with no flow set, because password was its fallback
branch. It now checks for `password` and returns an empty `OAuthFlows`
otherwise, so the v0.3 gRPC client does not read the empty flows as a
password flow.
## Tests
- `test_get_agent_card_with_device_code_oauth_flow`
(`test_grpc_handler.py`) serves a card with a device code scheme through
`CompatGrpcHandler.GetAgentCard`. On main it fails with the `ValueError`
above. With the fix the scheme comes back with empty flows.
- `test_oauth_flows_conversion` asserted that
`ToProto.oauth2_flows(OAuthFlows())` raises `ValueError`. It now checks
that the empty flows convert to an empty proto and back. The `FromProto`
half fails on main, where it returns a password flow.
- `uv run pytest tests/compat/v0_3`: 324 passed
- `bash scripts/lint.sh`: success. The 3 ruff diagnostics it prints are
in `client_factory.py` and `transports/__init__.py`, which this change
does not touch.
- `uv run pytest` on Windows, Python 3.11, skipping
`tests/integration/cross_version` and
`tests/integration/push_notifications` because they need `os.killpg` and
fork-based multiprocessing: 2549 passed, 207 skipped, 4 xfailed, 1
xpassed (with `PYTHONUTF8=1`, which `test_samples_smoke.py` needs on a
cp1252 console)
- [x] Follow the [`CONTRIBUTING`
Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md).
- [x] Make your Pull Request title in the
<https://www.conventionalcommits.org/> specification.
- [x] Ensure the tests and linter pass (Run `bash scripts/format.sh`
from the repository root to format)
- [x] Appropriate docs were updated (if necessary)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Mateusz Iwaniuk <45974414+Iwaniukooo11@users.noreply.github.com>1 parent 257626b commit 2ccef0d
6 files changed
Lines changed: 100 additions & 14 deletions
File tree
- src/a2a/compat/v0_3
- tests
- compat/v0_3
- integration/cross_version/client_server
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
577 | | - | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
578 | 580 | | |
579 | 581 | | |
580 | 582 | | |
| |||
1058 | 1060 | | |
1059 | 1061 | | |
1060 | 1062 | | |
1061 | | - | |
1062 | | - | |
1063 | | - | |
1064 | | - | |
1065 | | - | |
1066 | | - | |
1067 | | - | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
1068 | 1072 | | |
1069 | 1073 | | |
1070 | 1074 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
238 | | - | |
239 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
240 | 244 | | |
241 | 245 | | |
242 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
224 | 225 | | |
225 | 226 | | |
226 | 227 | | |
227 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
228 | 241 | | |
229 | 242 | | |
230 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
216 | 218 | | |
217 | 219 | | |
218 | 220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| |||
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
141 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
142 | 166 | | |
143 | 167 | | |
144 | 168 | | |
| |||
0 commit comments