a2a_protocol_types/generated/security.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Tom F. <[email protected]> (https://github.com/tomtom215)
3// @generated by tools/a2a-codegen from proto/a2a_v1/a2a.proto,
4// sha256 e195bf96ab630c69797851970203e1b2b6b19528f2e9803b7d904b91a5104016.
5// Included by the `security` module. Do not edit: change the proto or
6// crates/a2a-protocol-types/codegen.toml and regenerate (ADR 0016).
7
8/// A list of strings.
9///
10/// # Wire format
11///
12/// The spec's JSON is the ProtoJSON of that message, `{"list": ["read"]}`,
13/// and that is the only form emitted: `a2a.proto` is the normative
14/// definition of the data objects, the spec's own agent-card example writes
15/// `"schemes": {"google": {"list": ["openid", …]}}`, and the official Python
16/// SDK (`MessageToDict`) emits the same.
17///
18/// Three further forms are **accepted**, because real peers send them:
19///
20/// | Received | Read as | Who sends it |
21/// |---|---|---|
22/// | `{}` | empty | ProtoJSON printers omit an empty repeated field |
23/// | `["read"]` | `["read"]` | a2a-go v2.5.0 (`a2a/auth.go`: `Schemes map[…]SecuritySchemeScopes`) |
24/// | `null` | empty | a2a-go v2.5.0, for a nil scope slice |
25///
26/// Accepting the bare array is what lets this SDK read a Go agent's card at
27/// all. The other direction, a2a-go reading the spec form this SDK emits,
28/// needs a fix in a2a-go. `Deserialize` is written by hand, beside this type,
29/// to accept them.
30#[derive(Debug, Clone, serde::Serialize)]
31#[serde(rename_all = "camelCase")]
32#[non_exhaustive]
33pub struct StringList {
34 /// The individual string values.
35 ///
36 /// `ProtoJSON` printers omit empty repeated fields: an empty `StringList`
37 /// arrives as `{}`, so absence means empty (a scheme requiring no scopes
38 /// is common and valid).
39 pub list: Vec<String>,
40}
41
42/// Defines the security requirements for an agent.
43#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
44#[serde(rename_all = "camelCase")]
45#[non_exhaustive]
46pub struct SecurityRequirement {
47 /// A map of security schemes to the required scopes.
48 ///
49 /// `ProtoJSON` printers omit empty maps, so absence means empty.
50 #[serde(default)]
51 pub schemes: std::collections::HashMap<String, crate::security::StringList>,
52}
53
54/// Defines a security scheme that can be used to secure an agent's endpoints.
55///
56/// This is a discriminated union type based on the `OpenAPI` 3.2 Security Scheme Object.
57/// See: `https://spec.openapis.org/oas/v3.2.0.html#security-scheme-object`
58///
59/// # Wire format
60///
61/// In A2A v1.0 this is the `SecurityScheme` **`oneof`** from `a2a.proto`, so
62/// its ProtoJSON encoding is a single-key object naming the arm:
63///
64/// ```json
65/// {"apiKeySecurityScheme": {"location": "header", "name": "X-Api-Key"}}
66/// {"httpAuthSecurityScheme": {"scheme": "bearer", "bearerFormat": "JWT"}}
67/// ```
68///
69/// v0.3 used the OpenAPI-style internally tagged form instead
70/// (`{"type": "apiKey", "in": "header", …}`). **Both are accepted**; only the
71/// v1.0 form is emitted, because §5.5 governs emission and the schema is the
72/// normative definition of the JSON shape. `Serialize` and `Deserialize` are
73/// written by hand, beside this type, for that.
74///
75/// This changed in 0.8: earlier releases emitted the v0.3 form. A reference
76/// `a2a-sdk` client parsed that via its own legacy-compatibility shim, but a
77/// peer feeding the card straight to `ParseDict(…, ignore_unknown_fields=True)`
78/// silently got schemes with **empty contents** — it saw the agent declare
79/// authentication it could not use. See `docs/official-tck-findings.md` §7.
80#[derive(Debug, Clone)]
81#[non_exhaustive]
82pub enum SecurityScheme {
83 /// API key-based authentication.
84 ApiKey(crate::security::ApiKeySecurityScheme),
85 /// HTTP authentication (Basic, Bearer, etc.).
86 Http(crate::security::HttpAuthSecurityScheme),
87 /// OAuth 2.0 authentication.
88 ///
89 /// Boxed to reduce the enum's stack size.
90 OAuth2(Box<crate::security::OAuth2SecurityScheme>),
91 /// `OpenID` Connect authentication.
92 OpenIdConnect(crate::security::OpenIdConnectSecurityScheme),
93 /// Mutual TLS authentication.
94 MutualTls(crate::security::MutualTlsSecurityScheme),
95}
96
97/// Defines a security scheme using an API key.
98#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
99#[serde(rename_all = "camelCase")]
100#[non_exhaustive]
101pub struct ApiKeySecurityScheme {
102 /// An optional description for the security scheme.
103 #[serde(skip_serializing_if = "Option::is_none")]
104 pub description: Option<String>,
105 /// The location of the API key. Valid values are "query", "header", or "cookie".
106 ///
107 /// Emitted as `"location"`, the field name in `a2a.proto`. v0.3 called
108 /// this `"in"` (the OpenAPI spelling) and that spelling is still accepted,
109 /// so a card from an older peer still parses.
110 #[serde(alias = "in")]
111 pub location: crate::security::ApiKeyLocation,
112 /// The name of the header, query, or cookie parameter to be used.
113 pub name: String,
114}
115
116/// Defines a security scheme using HTTP authentication.
117#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
118#[serde(rename_all = "camelCase")]
119#[non_exhaustive]
120pub struct HttpAuthSecurityScheme {
121 /// An optional description for the security scheme.
122 #[serde(skip_serializing_if = "Option::is_none")]
123 pub description: Option<String>,
124 /// The name of the HTTP Authentication scheme to be used in the Authorization header,
125 /// as defined in RFC7235 (e.g., "Bearer").
126 /// This value should be registered in the IANA Authentication Scheme registry.
127 pub scheme: String,
128 /// A hint to the client to identify how the bearer token is formatted (e.g., "JWT").
129 /// Primarily for documentation purposes.
130 #[serde(alias = "bearer_format", skip_serializing_if = "Option::is_none")]
131 pub bearer_format: Option<String>,
132}
133
134/// Defines a security scheme using OAuth 2.0.
135#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
136#[serde(rename_all = "camelCase")]
137#[non_exhaustive]
138pub struct OAuth2SecurityScheme {
139 /// An optional description for the security scheme.
140 #[serde(skip_serializing_if = "Option::is_none")]
141 pub description: Option<String>,
142 /// An object containing configuration information for the supported OAuth 2.0 flows.
143 pub flows: crate::security::OAuthFlows,
144 /// URL to the OAuth2 authorization server metadata \[RFC `8414](https://datatracker.ietf.org/doc/html/rfc8414`).
145 /// TLS is required.
146 #[serde(alias = "oauth2_metadata_url", skip_serializing_if = "Option::is_none")]
147 pub oauth2_metadata_url: Option<String>,
148}
149
150/// Defines a security scheme using `OpenID` Connect.
151#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
152#[serde(rename_all = "camelCase")]
153#[non_exhaustive]
154pub struct OpenIdConnectSecurityScheme {
155 /// An optional description for the security scheme.
156 #[serde(skip_serializing_if = "Option::is_none")]
157 pub description: Option<String>,
158 /// The \[OpenID Connect Discovery `URL](https://openid.net/specs/openid-connect-discovery-1_0.html`) for the OIDC provider's metadata.
159 #[serde(alias = "open_id_connect_url")]
160 pub open_id_connect_url: String,
161}
162
163/// Defines a security scheme using `mTLS` authentication.
164#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
165#[serde(rename_all = "camelCase")]
166#[non_exhaustive]
167pub struct MutualTlsSecurityScheme {
168 /// An optional description for the security scheme.
169 #[serde(skip_serializing_if = "Option::is_none")]
170 pub description: Option<String>,
171}
172
173/// Defines the configuration for the supported OAuth 2.0 flows.
174///
175/// Per the proto definition, this is a `oneof flow` — exactly one flow type
176/// can be specified. Serialized as an externally tagged enum in JSON.
177#[derive(Debug, Clone, serde::Serialize)]
178#[serde(rename_all = "camelCase")]
179#[non_exhaustive]
180pub enum OAuthFlows {
181 /// Configuration for the OAuth Authorization Code flow.
182 AuthorizationCode(crate::security::AuthorizationCodeFlow),
183 /// Configuration for the OAuth Client Credentials flow.
184 ClientCredentials(crate::security::ClientCredentialsFlow),
185 /// Deprecated: Use Authorization Code + PKCE instead.
186 ///
187 /// Kept so cards that still declare it parse (spec §1.4: deprecated
188 /// definitions stay until the next major version), and marked
189 /// `#[deprecated]` as the proto marks the field:
190 ///
191 /// ```compile_fail
192 /// #[deny(deprecated)]
193 /// fn implicit(f: &a2a_protocol_types::security::OAuthFlows) -> bool {
194 /// matches!(f, a2a_protocol_types::security::OAuthFlows::Implicit(_))
195 /// }
196 /// ```
197 #[deprecated(
198 since = "0.15.0",
199 note = "deprecated in A2A 1.0; use Authorization Code + PKCE"
200 )]
201 Implicit(crate::security::ImplicitFlow),
202 /// Deprecated: Use Authorization Code + PKCE or Device Code.
203 ///
204 /// Kept and marked as [`Implicit`](Self::Implicit) is:
205 ///
206 /// ```compile_fail
207 /// #[deny(deprecated)]
208 /// fn password(f: &a2a_protocol_types::security::OAuthFlows) -> bool {
209 /// matches!(f, a2a_protocol_types::security::OAuthFlows::Password(_))
210 /// }
211 /// ```
212 #[deprecated(
213 since = "0.15.0",
214 note = "deprecated in A2A 1.0; use Authorization Code + PKCE or Device Code"
215 )]
216 Password(crate::security::PasswordOAuthFlow),
217 /// Configuration for the OAuth Device Code flow.
218 DeviceCode(crate::security::DeviceCodeFlow),
219}
220
221crate::oneof::oneof_deserialize!(
222 OAuthFlows,
223 [
224 AuthorizationCode(crate::security::AuthorizationCodeFlow) =
225 "authorizationCode" | "authorization_code",
226 ClientCredentials(crate::security::ClientCredentialsFlow) =
227 "clientCredentials" | "client_credentials",
228 Implicit(crate::security::ImplicitFlow) = "implicit",
229 Password(crate::security::PasswordOAuthFlow) = "password",
230 DeviceCode(crate::security::DeviceCodeFlow) = "deviceCode" | "device_code",
231 ]
232);
233
234/// Defines configuration details for the OAuth 2.0 Authorization Code flow.
235#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
236#[serde(rename_all = "camelCase")]
237#[non_exhaustive]
238pub struct AuthorizationCodeFlow {
239 /// The authorization URL to be used for this flow.
240 #[serde(alias = "authorization_url")]
241 pub authorization_url: String,
242 /// The token URL to be used for this flow.
243 #[serde(alias = "token_url")]
244 pub token_url: String,
245 /// The URL to be used for obtaining refresh tokens.
246 #[serde(alias = "refresh_url", skip_serializing_if = "Option::is_none")]
247 pub refresh_url: Option<String>,
248 /// The available scopes for the OAuth2 security scheme.
249 ///
250 /// ProtoJSON omits an empty map, so a peer's card with no scopes arrives
251 /// without the key; absence means empty, as for `StringList::list`.
252 #[serde(default)]
253 pub scopes: std::collections::HashMap<String, String>,
254 /// Indicates if PKCE (RFC 7636) is required for this flow.
255 /// PKCE should always be used for public clients and is recommended for all clients.
256 #[serde(alias = "pkce_required", skip_serializing_if = "Option::is_none")]
257 pub pkce_required: Option<bool>,
258}
259
260/// Defines configuration details for the OAuth 2.0 Client Credentials flow.
261#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
262#[serde(rename_all = "camelCase")]
263#[non_exhaustive]
264pub struct ClientCredentialsFlow {
265 /// The token URL to be used for this flow.
266 #[serde(alias = "token_url")]
267 pub token_url: String,
268 /// The URL to be used for obtaining refresh tokens.
269 #[serde(alias = "refresh_url", skip_serializing_if = "Option::is_none")]
270 pub refresh_url: Option<String>,
271 /// The available scopes for the OAuth2 security scheme.
272 ///
273 /// ProtoJSON omits an empty map, so a peer's card with no scopes arrives
274 /// without the key; absence means empty, as for `StringList::list`.
275 #[serde(default)]
276 pub scopes: std::collections::HashMap<String, String>,
277}
278
279/// Deprecated: Use Authorization Code + PKCE instead.
280#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
281#[serde(rename_all = "camelCase")]
282#[non_exhaustive]
283pub struct ImplicitFlow {
284 /// The authorization URL to be used for this flow. This MUST be in the
285 /// form of a URL. The OAuth2 standard requires the use of TLS
286 #[serde(alias = "authorization_url")]
287 pub authorization_url: String,
288 /// The URL to be used for obtaining refresh tokens. This MUST be in the
289 /// form of a URL. The OAuth2 standard requires the use of TLS.
290 #[serde(alias = "refresh_url", skip_serializing_if = "Option::is_none")]
291 pub refresh_url: Option<String>,
292 /// The available scopes for the OAuth2 security scheme. A map between the
293 /// scope name and a short description for it. The map MAY be empty.
294 ///
295 /// ProtoJSON omits an empty map, so a peer's card with no scopes arrives
296 /// without the key; absence means empty, as for `StringList::list`.
297 #[serde(default)]
298 pub scopes: std::collections::HashMap<String, String>,
299}
300
301/// Deprecated: Use Authorization Code + PKCE or Device Code.
302#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
303#[serde(rename_all = "camelCase")]
304#[non_exhaustive]
305pub struct PasswordOAuthFlow {
306 /// The token URL to be used for this flow. This MUST be in the form of a URL.
307 /// The OAuth2 standard requires the use of TLS.
308 #[serde(alias = "token_url")]
309 pub token_url: String,
310 /// The URL to be used for obtaining refresh tokens. This MUST be in the
311 /// form of a URL. The OAuth2 standard requires the use of TLS.
312 #[serde(alias = "refresh_url", skip_serializing_if = "Option::is_none")]
313 pub refresh_url: Option<String>,
314 /// The available scopes for the OAuth2 security scheme. A map between the
315 /// scope name and a short description for it. The map MAY be empty.
316 ///
317 /// ProtoJSON omits an empty map, so a peer's card with no scopes arrives
318 /// without the key; absence means empty, as for `StringList::list`.
319 #[serde(default)]
320 pub scopes: std::collections::HashMap<String, String>,
321}
322
323/// Defines configuration details for the OAuth 2.0 Device Code flow (RFC 8628).
324///
325/// This flow is designed for input-constrained devices such as `IoT` devices,
326/// and CLI tools where the user authenticates on a separate device.
327#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
328#[serde(rename_all = "camelCase")]
329#[non_exhaustive]
330pub struct DeviceCodeFlow {
331 /// The device authorization endpoint URL.
332 #[serde(alias = "device_authorization_url")]
333 pub device_authorization_url: String,
334 /// The token URL to be used for this flow.
335 #[serde(alias = "token_url")]
336 pub token_url: String,
337 /// The URL to be used for obtaining refresh tokens.
338 #[serde(alias = "refresh_url", skip_serializing_if = "Option::is_none")]
339 pub refresh_url: Option<String>,
340 /// The available scopes for the OAuth2 security scheme.
341 ///
342 /// ProtoJSON omits an empty map, so a peer's card with no scopes arrives
343 /// without the key; absence means empty, as for `StringList::list`.
344 #[serde(default)]
345 pub scopes: std::collections::HashMap<String, String>,
346}