Repository navigation
feat: add explicit OAuth token refresh support - #143
Merged
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f5c79efc-51d8-4913-8961-701522797f9e
babakks
requested review from
niik
and
a lite review from Copilot
and removed request for
Copilot
September 14, 2026 23:42
Signed-off-by: Babak K. Shandiz <babakks@github.com>
babakks
force-pushed
the
babakks/add-refresh-token-support
branch
from
September 14, 2026 23:46
20fbfd1 to
cde372e
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Standard invalid_grant refresh failures are not mapped to ErrRefreshTokenInvalid, and the README example references unavailable API methods.
Get a fresh assessment by requesting another Copilot review.
Review tier: Lite
Findings: 1
Open (2)
What changed in this PR
Adds OAuth token refresh support, token expiry metadata, and offline_access opt-in for web and device flows.
Changes:
- Adds refresh-token exchange and invalid-token error handling.
- Parses access and refresh token expiry values.
- Updates flows, documentation, examples, tests, and CI workflows.
| File | Reviewed change |
|---|---|
refresh.go |
Implements token refresh exchanges. |
refresh_test.go |
Tests refresh behavior and errors. |
README.md |
Documents refresh usage. |
oauth.go |
Adds refresh-token flow configuration. |
oauth_webapp.go |
Adds offline_access to web scopes. |
oauth_test.go |
Tests scope handling. |
oauth_device.go |
Adds offline_access to device scopes. |
examples_test.go |
Adds a refresh example. |
api/access_token.go |
Parses token expiry metadata. |
api/access_token_test.go |
Tests expiry parsing. |
.github/workflows/lint.yml |
Updates lint workflow dependencies. |
.github/workflows/ci.yml |
Updates CI actions and Go versions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
williammartin
requested review from
williammartin
and removed request for
niik
October 2, 2026 09:13
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
williammartin
force-pushed
the
babakks/add-refresh-token-support
branch
from
October 2, 2026 10:12
b9a715f to
4beee3a
Compare
williammartin
approved these changes
Oct 2, 2026
williammartin
left a comment
Member
There was a problem hiding this comment.
LGTM. Left a few non-blocking notes on things we might come back to once the cli/cli stack has landed.
RFC 6749 section 6 lets a server omit refresh_token from a refresh response, meaning the previous refresh token stays valid. Returning an empty RefreshToken would make callers that persist the result lose a usable refresh token, so fall back to the one passed in RefreshOptions and leave enforcing rotation to the application. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
Rotation is optional per the OAuth spec, so the README now attributes it to GitHub and notes that Refresh falls back to the previous refresh token when the server does not return a new one. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
Both flows added offline_access to the requested scopes in the same way, so move that logic onto Flow as requestedScopes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
ExpiresIn and RefreshTokenExpiresIn were int seconds, so every caller had to convert them before doing time arithmetic. Both fields are new and unreleased, so switch them to time.Duration now. The wire format is still parsed as seconds, and device.DeviceCode.ExpiresIn is unchanged since it is already part of the released API. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
The lint workflow installs the latest stable Go, now 1.27.3, whose export data golangci-lint v2.13.2 cannot decode, so every package failed typecheck. v2.14.0 is built with Go 1.27. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
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.


Description
Adds explicit OAuth token refresh support, consumed by the refreshable (short-lived) token stack in
cli/cli.Refreshfunction (refresh.go) exchanges a refresh token at the token endpoint for a new access and refresh token pair. It comes withRefreshOptionsand a distinctErrRefreshTokenInvalid, so callers can tell a permanently rejected refresh token from a transient failure and avoid pointless retries.api.AccessTokengainsExpiresInandRefreshTokenExpiresIn, parsed from the token response, so callers know when the access and refresh tokens expire. Zero means the server returned no expiry metadata.Flow.RequestRefreshTokenopts an authorization into an expiring access token plus a refresh token by adding theoffline_accessscope. Servers that do not support it simply return an ordinary non-expiring token with no refresh token.How did you test this change?
Unit tests:
refresh_test.gocovers the refresh exchange (success, empty and rejected refresh tokens, error mapping);access_token_test.goandoauth_test.gocover expiry parsing and theoffline_accessopt-in. The README and runnable examples are updated. Also bumps workflow action versions.