Skip to main content

Module oidc

Module oidc 

Source
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 TraceVault 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 TraceVault 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§

DeviceAuth
A started device authorization (RFC 8628 §3.2).
Discovery
The subset of the realm’s OpenID discovery document the CLI uses.
PublicConfig
What the TraceVault server publishes about its identity provider.
TokenSet
A successful token response. expires_in is relative seconds as sent by the IdP; callers turn it into an absolute instant via TokenSet::access_expires_at.

Enums§

OidcError
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) or OidcError::Transport (we never got a usable answer).

Constants§

LOGIN_SCOPE
Scopes requested for the device flow. offline_access is 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/v and https://x/realms/v/ match.
device_start
Start a device authorization (RFC 8628 §3.1). tracing-cli is a PUBLIC client, so the form carries client_id and no client secret.
discover
Fetch and validate the realm’s OpenID discovery document.
fetch_public_config
Ask the TraceVault server which realm to authenticate against.
is_browser_safe
Whether url is 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 aud claim of a JWT, read WITHOUT verifying the signature.