Repository navigation
fix(gh auth status): explain expired expiring tokens with --no-refresh - #14815
Merged
Merged
Conversation
With --no-refresh, an expiring token past its expiry fails the scope check and was reported as invalid, with a hint to run gh auth refresh. Report it as expired instead, show its expiry details, and hint at running gh auth status without --no-refresh, or gh auth login if the refresh token has also expired. Fixes #14814 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
--no-refresh
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unrelated API and transport failures can incorrectly trigger expiry-specific recovery advice.
1 open issue
What changed in this PR
This PR improves gh auth status --no-refresh diagnostics for expired OAuth tokens, addressing #14814 while preserving JSON output and exit behavior.
Changes:
- Show expiry details and recovery advice for expired tokens when refresh is disabled.
- Reuse expiry formatting across successful and expired entries.
- Add tests for expired access tokens, expired refresh tokens, and rejected unexpired tokens.
| File | Description |
|---|---|
pkg/cmd/auth/status/status.go |
Adds expiry detection, recovery hints, and shared expiry formatting. |
pkg/cmd/auth/status/status_test.go |
Covers the new diagnostics and existing invalid-token wording. |
Review effort: Balanced
Unrelated failures such as HTTP 503 or non-timeout transport errors do not indicate the token was rejected, so they keep the generic error output instead of the expiry-specific refresh or login hint. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
BagToad
approved these changes
Oct 26, 2026
1 task
This was referenced Oct 29, 2026
This was referenced Oct 31, 2026
1 task
1 task
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.

Fixes #14814
Description
gh auth statusrefreshes expiring OAuth tokens (gh auth login --expiring) automatically, unless--no-refreshis given. With--no-refresh, an access token past its expiry time is sent as is to the scope check, the API answers 401, and the entry falls into the generic error branch. The output then claims the token is invalid and suggestsgh auth refresh, which runs the full interactive OAuth flow again. In reality the token has only expired, and dropping--no-refresh(or running any other gh command) renews it.This change detects that case and explains it instead:
Before:
After:
If the refresh token has also expired, the last line suggests
gh auth login -h <host>instead, since a refresh can no longer succeed.How did you test this change?
With an expiring token whose access token had already expired, I ran
gh auth status --no-refreshusing a binary built from this branch and saw:Key points
--no-refresh. Without it, an expired token is refreshed before the scope check, and a rejected refresh token already has its ownrefresh_expiredstate.state: "error"and the raw API error. It already carriesrefreshableandtokenExpiresAt, which is enough for scripts to tell the cause apart.writeExpiryhelper so the success and expired outputs render them identically.Notes for reviewers
All changes are in
pkg/cmd/auth/status/status.go: start at theexpiredWithoutRefreshassignment inbuildEntry, then the new branch at the top of theauthEntryStateErrorcase inauthEntry.String. The new test cases sit next to the existing--no-refreshcases instatus_test.go.Authorship and follow-up
Who wrote this:
Who answers review comments: