feat(clients): google service-account OAuth and per-endpoint credential choice

ServiceAccountAuth signs an RS256 JWT with wolfCrypt from the key file in
GOOGLE_APPLICATION_CREDENTIALS and exchanges it for a self-refreshing bearer
token. GoogleClient holds a key and an OAuth credential and uses OAuth
everywhere except express endpoints, which only accept the key. Signing is
tested with generated RSA keys and public-key verification.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 04:29:58 +02:00
co-authored by Claude Sonnet 5.5
parent 6d744a433f
commit 90629bbbfc
11 changed files with 493 additions and 7 deletions
+9 -2
View File
@@ -17,6 +17,7 @@ client, credentials, errors, or caps.
| `caps.h` | Static ceilings, never autotuned |
| `errors.h/.cpp` | `GoogleError` (http status, Google status, message), `NotConfiguredError`, parser for Google's `{"error":{...}}` body |
| `credentials.h/.cpp` | `Credentials`: API key and OAuth bearer providers, env loader |
| `service_account.h/.cpp` | `ServiceAccountKey`, `JwtSigner` (RS256), `ServiceAccountAuth` (self-refreshing bearer) |
| `endpoints.h/.cpp` | `ServiceEndpoint` plus the catalog of known services |
| `client.h/.cpp` | `GoogleClient`: auth, JSON in/out, error mapping, over any `clients::Transport` |
| `service.h/.cpp` | `Service` base class: holds client plus endpoint, one `call()` |
@@ -44,6 +45,10 @@ client, credentials, errors, or caps.
## 3. Contracts
- Two credentials per client: an API key and an OAuth credential (bearer
token or service account via `GOOGLE_APPLICATION_CREDENTIALS`). OAuth is
used for every endpoint except express ones (`ServiceEndpoint::prefer_key`,
the Vertex express voice path), which only accept the key.
- Credentials: `GOOGLE_API_KEY` is read once by `GoogleClient::from_env()`
from the process environment, else `.env.json.local` (git-ignored, put
secrets here), else `.env.json`, in the working directory. All env knobs
@@ -84,8 +89,10 @@ client, credentials, errors, or caps.
- Streaming recognition (gRPC/WebSocket) and the Gemini Live API are not
implemented; turns are request/response over REST.
- Service-account JWT exchange for OAuth tokens: callers pass a ready token
to `Credentials::bearer`. Owner: this part, `credentials.cpp`.
- Service-account OAuth is implemented (`service_account.h`: RS256 JWT via
wolfCrypt, token exchange, refresh 60 s before expiry) and its signing is
tested with real RSA keys. The token exchange against Google itself is
unverified until a key file is configured (`GOOGLE_APPLICATION_CREDENTIALS`).
- Free-tier quota accounting is Google's; `RESOURCE_EXHAUSTED` is surfaced,
not tracked.
- Live behavior against Google needs a real `GOOGLE_API_KEY`; the suite