yaiam: device-flow sign-in for Yetano programs (YAIAM-710)

A shared client for programs that sign in at yaiam (or any OIDC
provider): device flow (RFC 8628), refresh with rotation, revocation
(RFC 7009), UserInfo and a 0600 file store. Standard library only;
https only (http on loopback), exact issuer match, no redirects,
answers capped at 1 MiB, tokens never in errors or fmt output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-11-09 21:40:58 +01:00
1 parent 6a97dbd4c6
commit 4bff8798e5
7 files changed
+1245 -1

No files matched your search

+37
View File
@@ -14,9 +14,13 @@ 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) |
Standard library only, no third-party dependencies.
`yaiam` signs a command-line program in at yaiam (device flow) and keeps
its tokens; see below.
## Usage
```go
@@ -107,6 +111,39 @@ make # fmt + vet + test (-race) + vulncheck
make test
```
## yaiam
A command-line program signs its user in at yaiam -- or any OpenID
Connect provider with the device flow -- and keeps the tokens:
```go
c := &yaiam.Client{Issuer: "https://login.example.org/t/default", ClientID: id}
store := yaiam.FileStore{Path: filepath.Join(stateDir, "token.json")}
c.Login(ctx, store, func(d *yaiam.DeviceAuth) error {
fmt.Printf("Open %s and enter %s\n", d.VerificationURI, d.UserCode)
return nil
})
err := c.Authorize(ctx, store, req) // Bearer header; refreshes when needed
c.Logout(ctx, store) // revokes at the provider, forgets them
```
- Only standards: discovery, device authorization, token endpoint
(device code, refresh token), revocation (RFC 7009), UserInfo. A
public client, no secret.
- `FileStore` keeps the tokens in a 0600 file and refuses one others
may read. A stored token is used only for its own issuer and client;
a refused refresh token removes it (`ErrLoginRequired`).
- Every endpoint must be https (http only on a loopback host), the
discovery document must name exactly the issuer, redirects are never
followed, answers are capped at 1 MiB. Tokens appear in no error, and
`fmt` prints a `Token` without them.
- Checking tokens on the server side is not here: yaiam's
`pkg/httpauth` (JWT against the issuer's keys, optional
introspection).
The user's guide is yaiam's `docs/manual/yetano-programme.md`; an
example program is yaiam's `examples/device-login`.
## Versioning
A release is a plain semver git tag (`v0.1.0`, ...) on this repository;