|
| 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 | +} |
0 commit comments