feat(yaiam): token exchange for a user's token at another service (RFC 8693)

Exchanger trades a user's access token, as a confidential client with
its secret in a Basic header, for one at another yaiam client (yaiam
ADR-0045): Exchange(ctx, subject, audience, scopes...) and Revoke for
the end of an agent's job. Only access tokens are asked for and taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-11-21 19:27:57 +01:00
1 parent 76543b23a0
commit 560a1ead8a
4 files changed
+293 -1

No files matched your search

+27 -1
View File
@@ -14,7 +14,7 @@ Today it holds the Atlassian clients that `yareco`, `yabaratla` and
| `atlassian/jira` | Jira REST API client (Cloud v3 and Server/Data Center v2) |
| `atlassian/confluence` | small Confluence REST API client (classic content API) |
| `atlassian/internal/transport` | the HTTP machinery both share; not importable from outside |
| `yaiam` | sign a command-line program in at yaiam (device flow, RFC 8628) and keep its tokens (YAIAM-710, 2026-11-09); sign a web application's users in (code flow with PKCE) and read users and groups from yaiam's admin API (2026-11-17) |
| `yaiam` | sign a command-line program in at yaiam (device flow, RFC 8628) and keep its tokens (YAIAM-710, 2026-11-09); sign a web application's users in (code flow with PKCE) and read users and groups from yaiam's admin API (2026-11-17); trade a user's token for one at another service, for an agent (token exchange, RFC 8693, 2026-11-21) |
Standard library only, no third-party dependencies.
@@ -188,6 +188,32 @@ An example web application is yaiam's `examples/webapp`; an end-to-end
test against a real yaiam-authd is yaiam's
`internal/oidcprovider/weblogin_test.go`.
### Acting for a user: token exchange
A confidential client that holds a user's access token -- an
application, a gateway, an agent runner like yaais -- trades it for one
at another client of yaiam, on behalf of the same user (RFC 8693, yaiam
ADR-0045). The target has to allow it (`yaiam-ctl client exchange-from
<target> <this client>`):
```go
x := &yaiam.Exchanger{
Client: yaiam.Client{Issuer: "https://login.example.org/t/default", ClientID: yaaisID},
ClientSecret: secret, // its token endpoint auth method is basic
}
agent, err := x.Exchange(ctx, usersAccessToken, yakpoClientID) // optional: fewer scopes
// ... the agent calls yakpo with agent.AccessToken ...
x.Revoke(ctx, agent) // at the end of its job: only this token ends
```
The new token names the user (`sub`), this client (`client_id`,
`act.sub`) and the target alone (`aud`). It has no refresh token and
ends no later than the user's token; when that one ends (revoked, the
consent withdrawn), so does the exchanged one. Give an agent the
exchanged token, never the user's. The user's token may be one issued to
this client or one another client got for it as its audience (an MCP
client calling a gateway).
## Versioning
A release is a plain semver git tag (`v0.1.0`, ...) on this repository;