Expand description
OIDC / OAuth 2.0 plumbing for interactive (human) login.
The CLI authenticates humans with Keycloak’s RFC 8628 device
authorization grant: it asks the Visdom server which realm to talk to
(/api/v1/auth/public-config), discovers the realm’s endpoints, starts a
device authorization, polls the token endpoint until the user finishes in
the browser, and thereafter keeps the access token fresh with the refresh
token. The Visdom server itself is not part of the token exchange —
it only publishes the issuer and client id.
Everything here is transport + protocol only: no printing, no credential file access, no command-layer concerns. That keeps the whole module testable against a raw one-shot HTTP server.
§Secret hygiene
device_code, access_token and refresh_token are secrets. DeviceAuth
and TokenSet therefore implement Debug by hand, redacting those
fields, so no {:?} anywhere (including a panicking unwrap() inside a
test) can leak them into a log. For the same reason no error variant in
OidcError carries a response body: an IdP error body is not supposed
to contain a token, but a success body always does, and one shared
“here is the body” error path would eventually be reached from a success
response that failed to deserialize.
Structs§
- Device
Auth - A started device authorization (RFC 8628 §3.2).
- Discovery
- The subset of the realm’s OpenID discovery document the CLI uses.
- Public
Config - What the Visdom server publishes about its identity provider.
- Token
Set - A successful token response.
expires_inis relative seconds as sent by the IdP; callers turn it into an absolute instant viaTokenSet::access_expires_at.
Enums§
- Oidc
Error - Failures of the login/refresh machinery. Every variant that a caller has
to behave differently about is its own variant; anything else collapses
into
OidcError::Oauth(the IdP said no, with a code) orOidcError::Transport(we never got a usable answer).
Constants§
- LOGIN_
SCOPE - Scopes requested for the device flow.
offline_accessis what makes Keycloak issue a long-lived refresh token, which is the whole point of this flow for a CLI: unattended git hooks must never prompt.
Functions§
- canonical_
issuer - Canonical form of an issuer URL for comparison: no surrounding
whitespace, no trailing slashes. Both the configured issuer and the one
the discovery document self-reports go through this before being
compared, so
https://x/realms/vandhttps://x/realms/v/match. - device_
start - Start a device authorization (RFC 8628 §3.1).
tracing-cliis a PUBLIC client, so the form carriesclient_idand no client secret. - discover
- Fetch and validate the realm’s OpenID discovery document.
- fetch_
public_ config - Ask the Visdom server which realm to authenticate against.
- is_
browser_ safe - Whether
urlis safe to hand to the desktop’s URL handler. - poll_
token_ with - Poll the token endpoint until the user approves, or the attempt dies.
- refresh
- Exchange a refresh token for a fresh access token.
- revoke
- Best-effort revocation of a refresh token (RFC 7009). Called by
tv logout; a failure there is a warning, not an error, because the local credential is removed regardless. - unverified_
audiences - The
audclaim of a JWT, read WITHOUT verifying the signature.