Skip to content

[FEATURE] Implement Authentication command #4

Description

@edenreich

Summary

Add an a2a auth <token> command that verifies a bearer token against an A2A server, plus the global --token / --auth-header flags that every other command (tasks *, interactive, agent-card) needs to talk to an auth-enabled server at all. Today the debugger has no way to send credentials: initA2AClient() in cli/cli.go builds the ADK client with an empty Headers map, so any server started with A2A_AUTH_ENABLED=true answers 401 to everything except the public card.

Obtaining the token stays out of band (cURL against the IdP); the debugger only transmits it. That matches the A2A spec: authentication is card-driven, the client never runs an OAuth flow in-protocol.

How authentication works in A2A (context for the implementer)

Spec: https://a2a-protocol.org/latest/specification/#7-authentication-and-authorization and the extended-card contract in 3.3.4. ADK write-up: https://github.com/inference-gateway/adk/blob/v0.26.4/docs/authentication.md

  1. GET /.well-known/agent-card.json is always unauthenticated. The card advertises securitySchemes (named schemes: apiKey, http, oauth2, openIdConnect, mutualTLS), security (OR-of-ANDs requirement list) and supportsExtendedAgentCard.
  2. The client obtains a credential out of band and sends it on every request. The ADK server middleware (server/middlewares/auth.go) only understands Authorization: Bearer <jwt> and verifies the JWT against the configured OIDC issuer; other schemes are declared on the card but not enforced by ADK.
  3. Missing header -> HTTP 401 + WWW-Authenticate: Bearer. Wrong format -> 401 + error="invalid_request". Bad/expired token -> 401 + error="invalid_token". The ADK client surfaces these as unexpected status code: 401, body: {"error":"..."}.
  4. An authenticated client calls JSON-RPC agent/getAuthenticatedExtendedCard on POST /a2a. Error contract: -32004 when the card does not set supportsExtendedAgentCard, -32007 when the flag is set but no extended card is configured, otherwise the extended card.

Getting a token for a local test (Keycloak realm shipped in adk/examples/authentication/docker-compose.yaml):

TOKEN=$(curl -s http://localhost:8080/realms/inference-gateway-realm/protocol/openid-connect/token \
  -d grant_type=password -d client_id=inference-gateway-client \
  -d client_secret=inference-gateway-secret -d username=demo -d password=demo -d scope=openid \
  | jq -r .access_token)
a2a auth "$TOKEN" --server-url http://localhost:8090

Implementation path

Everything already exists in the ADK client (github.com/inference-gateway/adk/client v0.26.4); this is wiring only, all in cli/cli.go plus README.

  1. Global flags, bound to viper like the existing ones (in init()):

    • --token (string, default empty): bearer token / credential value.
    • --auth-header (string, default Authorization): header that carries the token.
      Because they are viper keys, a2a config set token <jwt> and env vars work for free with no new persistence code. Document that config set writes the token in plaintext to ~/.a2a.yaml and that env / flag is preferred.
  2. Attach the credential in initA2AClient() so every command and the interactive mode inherit it:

    if token := viper.GetString("token"); token != "" {
        name := viper.GetString("auth-header")
        if strings.EqualFold(name, "Authorization") && !strings.HasPrefix(token, "Bearer ") {
            token = "Bearer " + token
        }
        config.Headers[name] = token
    }

    client.Config.Headers is applied by setHeaders() to every JSON-RPC and streaming request. Note: GetAgentCard and GetHealth deliberately do not send custom headers (public endpoints), which is correct per spec.

  3. auth command on rootCmd, Args: cobra.ExactArgs(1), registered next to connectCmd:

    • viper.Set("token", args[0]) then ensureA2AClient() (reuses step 2, no second code path).

    • a2aClient.GetAgentCard(ctx): fail fast if unreachable. Keep the card for the output.

    • If card.SupportsExtendedAgentCard is nil/false: print authenticated: false with a clear reason and the card's securitySchemes, exit 1. Do not call the RPC, the server would answer -32004 regardless of the token.

    • a2aClient.GetAuthenticatedExtendedCard(ctx, adk.GetAuthenticatedExtendedCardParams{}), unmarshal resp.Result into adk.AgentCard (same json.Marshal / Unmarshal round-trip the other commands use).

    • Success output through printFormatted so -o json|yaml is honored:

      authenticated: true
      header: Authorization
      security_schemes: { ... from the public card ... }
      extended_card: { ... }
    • Errors go through handleA2AError(err, "agent/getAuthenticatedExtendedCard"). Extend that helper with two more mappings alongside the existing -32601 one: -32007 -> "extended agent card not configured on the server", and an HTTP 401 body -> "authentication rejected: (check the token and --auth-header)". Non-zero exit on any failure so the command is usable in scripts.

  4. Tests in cli/cli_test.go using the existing mockA2AClient (it already implements GetAuthenticatedExtendedCard), following the save/restore a2aClient and os.Pipe stdout pattern:

    • happy path: extended card returned, output contains authenticated: true.
    • card without supportsExtendedAgentCard: exits with error, RPC not called.
    • RPC returns -32007 / a 401-shaped error: friendly message.
    • initA2AClient header composition: Authorization gets the Bearer prefix, a custom header (X-Api-Key) gets the raw value.
  5. Docs: README "Server Commands" (a2a auth <token>), "Global Options" (--token, --auth-header), a short "Authentication" example section with the cURL snippet above, and the new keys in the ~/.a2a.yaml example. AGENTS.md namespace list gets auth.

Acceptance Criteria

  • a2a auth <token> fetches the public card, calls agent/getAuthenticatedExtendedCard with the token, prints the extended card via printFormatted, exits 0 on success and 1 on any failure
  • The token is sent in the header named by --auth-header (default Authorization, value prefixed with Bearer for that header only)
  • --token / --auth-header are global, viper-bound flags, so tasks *, interactive and agent-card work against an auth-enabled server and a2a config set token ... persists them
  • 401, -32004 and -32007 produce actionable messages instead of raw ADK errors
  • Unit tests cover the happy path, the unsupported-card path, and the error mappings
  • README and AGENTS.md document the command, the flags, and how to obtain a token out of band

Out of scope

  • Running an OAuth / OIDC flow inside the debugger (spec 7.3: credential acquisition is out of band)
  • API key or mTLS enforcement (ADK only enforces OIDC bearer today)
  • Token refresh or secure storage beyond the existing ~/.a2a.yaml config file

Activity

  1. added
    enhancement
    on Aug 6, 2025
  2. added theissue type on Aug 6, 2025
  3. edenreich commented on Sep 14, 2026

    @edenreich
    ContributorAuthor

    @claude Can you work on this? use /ponytail:ponytail

  4. inference-gateway-maintainer commented on Sep 14, 2026

    @inference-gateway-maintainer
    Contributor

    Claude finished @edenreich's task in 4m 53s —— View job • feat/issue-4-20260914-2039 • Create PR ➔


    Done - a2a auth implemented

    • Read cli/cli.go and understand wiring
    • Global --token / --auth-header flags, viper-bound, injected in initA2AClient()
    • a2a auth <token> command on root
    • Error mappings for 401, -32004, -32007
    • Tests (happy path, unsupported card, error mappings, header composition)
    • README + AGENTS.md docs
    • go build, go vet, go test ./... - all pass
    • PR opened / Roadmap board updated - blocked, see note below

    What changed

    cli/cli.go

    • --token and --auth-header (default Authorization) persistent flags, viper-bound. The five repeated BindPFlag blocks collapsed into one loop over the key list.
    • New authHeader() helper returns the header name/value (Bearer prefix only when the header is Authorization and the token is not already prefixed); initA2AClient() puts it into client.Config.Headers, so tasks *, interactive and agent-card all inherit the credential.
    • authCmd: sets the token, fetches the public card, short-circuits with authenticated: false + the card's securitySchemes when supportsExtendedAgentCard is unset (RPC not called), otherwise calls agent/getAuthenticatedExtendedCard and prints authenticated / header / security_schemes / extended_card via printFormatted. Any failure returns an error, so the process exits 1.
    • handleA2AError now derives the JSON-RPC code once and maps -32601, -32004, -32007 and unexpected status code: 401 to friendly messages.

    cli/auth_test.go (new) + a getAuthenticatedExtendedCardFunc hook on the existing mockA2AClient: happy path, unsupported-card path (fails the test if the RPC is called), table test for the three error mappings, table test for header composition including X-Api-Key.

    Docs: README gets the command, the two global options, the config-file keys and an "Authentication" section with the Keycloak cURL snippet plus the plaintext-storage warning; AGENTS.md gets auth in the root namespace list and a short authentication note.

    Skipped: no OAuth flow, no token refresh or secure storage, no API-key/mTLS enforcement - all listed out of scope in the issue.

    Note

    The commit is pushed to feat/issue-4-20260914-2039, but this run's sandbox refused every gh invocation ("This command requires approval"), so I could not open the PR or set the Roadmap board item to In progress / QA. That is a local tool-permission limit, not a missing GitHub scope, so I did not file an escalation issue. Please open the PR with the link below and move the board item.

    | Branch: feat/issue-4-20260914-2039

  5. moved this from Todo to QA in 2026on Sep 14, 2026
  6. moved this from QA to Done in 2026on Sep 16, 2026
  7. inference-gateway-releaser commented on Oct 3, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.11.0 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementreleased

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions