refactor(cli): deduplicate token form params and renderer state#45
Merged
Conversation
- Extract client_secret and extra_claims form helpers shared by auth, browser, device, and revoke flows - Add a single helper for computing token expiry from a duration in seconds - Derive in-progress step state from the step index sentinel instead of a redundant boolean flag Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR refactors shared OAuth/token request logic in the CLI to reduce duplicated form parameter and expiry calculations, while simplifying flow-renderer state tracking without intended behavior changes.
Changes:
- Adds shared helpers for token expiry,
client_secret, andextra_claimsform parameters. - Replaces duplicated helper logic across browser, device, refresh, and revoke paths.
- Removes the redundant renderer boolean by using
-1as the no-active-step sentinel.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
tokens.go |
Adds shared helpers and uses expiry helper in token conversion. |
auth.go |
Uses shared helpers when refreshing access tokens. |
browser_flow.go |
Uses shared helpers during authorization-code exchange. |
device_flow.go |
Uses shared helpers for device-flow expiry and extra claims. |
token_cmd.go |
Uses shared helper for revoke client_secret handling. |
tui/flow_renderer.go |
Derives in-progress renderer state from the step index sentinel. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Behavior-preserving cleanup of the CLI's OAuth/token code. Deduplicates three repeated patterns into shared helpers and removes a redundant boolean in the flow renderer. No functional change — output from the
/simplifyreview pass.AI Authorship
auth.go,browser_flow.go,device_flow.go,token_cmd.go,tokens.go,tui/flow_renderer.goChange classification
setClientSecret/setExtraClaims/expiryFromNowhelpers are now on the shared token path used by every OAuth flow (browser, device, refresh, revoke). A defect here propagates system-wide, so it warrants close review despite being a pure refactor.What changed
client_secret(confidential-client) andextra_claimsform params into*AppConfig.setClientSecret/setExtraClaims, replacing four hand-inlined copies across the auth, browser, device, and revoke flowsexpiryFromNow(expiresIn int)for token-expiry math, replacing three copies oftime.Now().Add(time.Duration(x) * time.Second)hasInProgressStepbool inFlowRenderer; derive it from the existinginProgressStepIdxusing-1as the "none" sentinelVerification
go test ./...— bothcliandcli/tuipackages green)go build ./...,go vet ./...,gofmtall cleanVerifiability check
-1for no in-progress step) is initialized inNewFlowRendererand read in two derived sitesRisk & rollback
inProgressStepIdxmust be initialized to-1(done inNewFlowRenderer) so the spinner/redraw guards behave as before. The form-param helpers preserve the exact public/confidential-client and empty-claims conditionals.Reviewer guide
tokens.go(the three new helpers and thattokenResponseToCredstorestill computes the same expiry) and each call site inauth.go/browser_flow.go/device_flow.go/token_cmd.goto confirm the conditionals match the originals.tui/flow_renderer.go— verifyinProgressStepIdxinit to-1and the two>= 0/< 0guards; the rest is mechanical.🤖 Generated with Claude Code