Repository navigation
feat: add OAuth sign-in and a2a auth commands - #146
mykytanetipa wants to merge 1 commit into
Conversation
336f9d2 to
c6299c3
Compare
|
Ran this against a2a-go's oauthtest server with a few protected agents. Browser and device sign-in, silent refresh with rotation, Logout can reach other hosts though. A repo A plain 401 without a Bearer challenge also gets treated as a bad grant. |
Use a2aclient/oauth from a2a-go for discovery, sign-in, refresh and the client plugin that attaches tokens, and keep only what is specific to the CLI: - internal/oauthstore: the grant file in ~/.config/a2a-cli/oauth with its cross-process lock, which the Manager is given as its Locker, and which follows the a2a-go Store contract (grants by ID, Get reports ErrGrantNotFound, results are copies); on Windows a write retries briefly when another process has the file open. The --oauth-clients flag, with omit_resource and unknown fields rejected everywhere, and the a2a-cli Client ID Metadata Document. - internal/cli: --oauth, a2a auth login/logout/list, OAuth grants in a2a auth get, signing in and retrying when an agent requires it, the prompts for the browser and device flows with the redirect path the CIMD document lists, and exit code 4 with CREDENTIALS_MISSING or AUTH_FAILED. OAuth is off by default for agent calls, so agents reached with other credentials work as before; users turn it on with --oauth auto|cached, oauth: auto in the config, or A2ACLI_OAUTH, but not from a discovered .env. The a2a auth commands work in any mode, and the grant store is only opened when OAuth is used, so other commands still run without a home directory. With OAuth off, a 401 that asks for a Bearer token, including one for the agent card, gets a hint to sign in and retry with --oauth auto, unless the request carried an Authorization header of the user's. With OAuth on, the Manager's plugin attaches the stored grant, refreshes a token the agent rejects and repeats the call once, and reports calls that need a sign-in. Explicit credentials win: a credential helper runs as a plugin before OAuth, so a call that carries its Authorization, or one from --auth or --svc-param, is left to that credential, 401 included. When the user passes any --svc-param, has a credential helper for the agent's host, or uses --unix-socket, a card that requires OAuth doesn't stop the request before it is sent, also when its OAuth requirement can't be resolved, and OAuth signs in only when the agent answers with a Bearer challenge. A 401 without one is reported as the agent's error. Duplicate oauth-clients entries for one server are a usage error naming them, and auth logout refuses an argument that isn't an http(s) URL. When --insecure comes from a discovered .env, no OAuth token is sent over plaintext gRPC. A protected agent card is not an A2A call: its request carries the token from Manager.Token when a grant is stored, and its 401 leads to the sign-in through Manager.Discover, both when a command signs in and in auth login. auth login makes a real GetTask call, so it finds the requirement the way other commands do, including from a 401 to an agent that answers a bare GET with 404 or 405; when that needs no sign-in it reads the card or probes the interface with Manager.Discover. When no client registration matches, the error names the oauth-clients entry to add, or for a flow the card declares inline, the token endpoint whose server needs one. Ctrl-C during a sign-in is reported as an interrupted authorization. auth get and auth logout select the grant for exactly the URL given, and read the agent card to also select the grants for its interface URLs at or below that URL and, when the URL has a path, those below it. Grants for the card's other interfaces on the same origin, which may belong to other agents on a host that routes agents by path, are only listed, and interfaces on other origins are ignored, so one agent's card can't select another agent's grants. When the card can't be read they select only the exact grant. Other grants that may apply, such as one for the host shared by sibling agents, are listed by auth get and kept by auth logout with the command that removes each. Logout revokes through Manager.Revoke, which removes the grant even when the server can't revoke it. auth get with nothing stored fails with CREDENTIALS_MISSING, and its JSON always has the same keys. a2a server --proxy never uses OAuth for its upstream calls. Other commands only start a sign-in when stderr is a terminal, which /dev/null is not. a2a-go diagnostics go to the logger in the command context: with --verbose they are printed like other diagnostics, and otherwise the OAuth ones stay hidden.
c6299c3 to
742b432
Compare
Agree, all three are fixed: Logout now only removes grants at or below the URL you pass, so your 18999 repro leaves the other agent's grant alone. When --insecure comes from a discovered .env, OAuth tokens aren't sent over plaintext gRPC. And a 401 without a Bearer challenge is passed through as is, so task list just shows UNAUTHENTICATED. |
Adds OAuth sign-in to the a2a CLI, built on the a2a-go OAuth client. Once OAuth is turned on, a command whose agent needs a token signs the user in, stores the grant and runs again. Later commands reuse the grant and refresh it without prompts:
Key changes
This builds against the a2a-go OAuth client, which isn't released yet, so go.mod points at that branch for now. With that SDK, a JSON-RPC error without a JSON-RPC body, such as a 502 from a proxy, is reported as A2ACLI_ERR_PROTOCOL instead of A2ACLI_ERR_INTERNAL. Exit codes are unchanged.
Tested
Refs #98