Skip to content

Commit 065acea

Browse files
adamfweidmanAdib234
authored andcommitted
feat(core): Add A2A auth config types (#18205)
1 parent f3da8a3 commit 065acea

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* Client-side auth configuration for A2A remote agents.
9+
* Corresponds to server-side SecurityScheme types from @a2a-js/sdk.
10+
* @see https://a2a-protocol.org/latest/specification/#451-securityscheme
11+
*/
12+
13+
import type { AuthenticationHandler } from '@a2a-js/sdk/client';
14+
15+
export type A2AAuthProviderType =
16+
| 'google-credentials'
17+
| 'apiKey'
18+
| 'http'
19+
| 'oauth2'
20+
| 'openIdConnect';
21+
22+
export interface A2AAuthProvider extends AuthenticationHandler {
23+
readonly type: A2AAuthProviderType;
24+
initialize?(): Promise<void>;
25+
}
26+
27+
export interface BaseAuthConfig {
28+
agent_card_requires_auth?: boolean;
29+
}
30+
31+
/** Client config for google-credentials (not in A2A spec, Gemini-specific). */
32+
export interface GoogleCredentialsAuthConfig extends BaseAuthConfig {
33+
type: 'google-credentials';
34+
scopes?: string[];
35+
}
36+
37+
/** Client config corresponding to APIKeySecurityScheme. */
38+
export interface ApiKeyAuthConfig extends BaseAuthConfig {
39+
type: 'apiKey';
40+
/** The secret. Supports $ENV_VAR, !command, or literal. */
41+
key: string;
42+
/** Defaults to server's SecurityScheme.in value. */
43+
location?: 'header' | 'query' | 'cookie';
44+
/** Defaults to server's SecurityScheme.name value. */
45+
name?: string;
46+
}
47+
48+
/** Client config corresponding to HTTPAuthSecurityScheme. */
49+
export type HttpAuthConfig = BaseAuthConfig & {
50+
type: 'http';
51+
} & (
52+
| {
53+
scheme: 'Bearer';
54+
/** For Bearer. Supports $ENV_VAR, !command, or literal. */
55+
token: string;
56+
}
57+
| {
58+
scheme: 'Basic';
59+
/** For Basic. Supports $ENV_VAR, !command, or literal. */
60+
username: string;
61+
/** For Basic. Supports $ENV_VAR, !command, or literal. */
62+
password: string;
63+
}
64+
);
65+
66+
/** Client config corresponding to OAuth2SecurityScheme. */
67+
export interface OAuth2AuthConfig extends BaseAuthConfig {
68+
type: 'oauth2';
69+
client_id?: string;
70+
client_secret?: string;
71+
scopes?: string[];
72+
}
73+
74+
/** Client config corresponding to OpenIdConnectSecurityScheme. */
75+
export interface OpenIdConnectAuthConfig extends BaseAuthConfig {
76+
type: 'openIdConnect';
77+
issuer_url: string;
78+
client_id: string;
79+
client_secret?: string;
80+
target_audience?: string;
81+
scopes?: string[];
82+
}
83+
84+
export type A2AAuthConfig =
85+
| GoogleCredentialsAuthConfig
86+
| ApiKeyAuthConfig
87+
| HttpAuthConfig
88+
| OAuth2AuthConfig
89+
| OpenIdConnectAuthConfig;
90+
91+
export interface AuthConfigDiff {
92+
requiredSchemes: string[];
93+
configuredType?: A2AAuthProviderType;
94+
missingConfig: string[];
95+
}
96+
97+
export interface AuthValidationResult {
98+
valid: boolean;
99+
diff?: AuthConfigDiff;
100+
}

packages/core/src/agents/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { AnyDeclarativeTool } from '../tools/tools.js';
1313
import { type z } from 'zod';
1414
import type { ModelConfig } from '../services/modelConfigService.js';
1515
import type { AnySchema } from 'ajv';
16+
import type { A2AAuthConfig } from './auth-provider/types.js';
1617

1718
/**
1819
* Describes the possible termination modes for an agent.
@@ -108,6 +109,12 @@ export interface RemoteAgentDefinition<
108109
> extends BaseAgentDefinition<TOutput> {
109110
kind: 'remote';
110111
agentCardUrl: string;
112+
/**
113+
* Optional authentication configuration for the remote agent.
114+
* If not specified, the agent will try to use defaults based on the AgentCard's
115+
* security requirements.
116+
*/
117+
auth?: A2AAuthConfig;
111118
}
112119

113120
export type AgentDefinition<TOutput extends z.ZodTypeAny = z.ZodUnknown> =

0 commit comments

Comments
 (0)