fix(cli): don't render a non-expiring refresh token as expired#425
Draft
richard-pipefy wants to merge 1 commit into
Draft
fix(cli): don't render a non-expiring refresh token as expired#425richard-pipefy wants to merge 1 commit into
richard-pipefy wants to merge 1 commit into
Conversation
`pipefy auth status` computed the refresh-token expiry as `obtained_at + refresh_expires_in`. Keycloak sends `refresh_expires_in: 0` to advertise a non-expiring refresh token, but `_iso_expiry` reads `0` as a 0-second TTL and places expiry at the login instant — so the durable credential was always shown as `expired` (and `refresh_expires_at` was a past timestamp in `--json`). Eager refresh resets `obtained_at` to now on every rotation, so it stays perpetually "expired". Normalize the sentinel where the refresh token is read (`refresh_expires_in or None`), leaving `_iso_expiry` generic so a genuine 0-second access-token TTL still reads as expired. Purely a status-readout change; the refresh decision (`_is_stale`) never consults this value — it's only carried forward verbatim on rotation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pipefy auth statusalways showedRefresh token: expired(andrefresh_expires_atas a past timestamp in--json), even on a freshly-authenticated session — misleading users, and agents polling auth during long-running work, into thinking re-login is imminent.Refresh-token expiry is computed as
obtained_at + refresh_expires_in. Keycloak sendsrefresh_expires_in: 0to advertise a non-expiring refresh token, but that0was read as a 0-second TTL, placing expiry at the login instant. Eager refresh resetsobtained_atto now on every rotation, so it sat perpetually at ~now → perpetually "expired".Fix: normalize the sentinel where the refresh token is read (
refresh_expires_in or None), so0→ no expiry →unknown(text) /null(JSON)._iso_expirystays generic, so a genuine 0-second access-token TTL still reads as "expired". Purely a status-readout change; the refresh decision (_is_stale) never consults this value — it's only carried forward verbatim on rotation.Deliberately not rendered as "never": per Keycloak's issue tracker,
refresh_expires_in: 0doesn't guarantee the token never expires — with "Offline Session Max Limited" off but a non-zero "Offline Session Idle", the server still enforces an idle timeout and rejects refreshes withinvalid_grant.unknown/nullis the honest readout.Confirmed against a live session:
refresh_expires_in = 0,expires_in = 300, recentobtained_at.Testing performed
uv run --package pipefy-cli pytest packages/cli/tests/→ 341 passed, 13 skippeduv run ruff check packages/cli/src/pipefy_cli/commands/auth.py→ All checks passed!test_status_non_expiring_refresh_token_not_reported_expired(seedsrefresh_expires_in=0; asserts--jsonrefresh_expires_at is Noneand the text line is notexpired).Docs
docs/cli/auth.md: updated therefresh_expires_atJSON-schema note —nullnow also covers an active stored session whose refresh token advertises no expiry (refresh_expires_in: 0).