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.
| token, err := resp.AccessToken() | ||
| if err != nil { | ||
| var apiError *api.Error | ||
| if errors.As(err, &apiError) && apiError.Code == "bad_refresh_token" { |
| Before using an expired token, exchange its refresh token and persist the returned token pair: | ||
|
|
||
| ```go | ||
| if token.IsExpired() && token.CanRefresh() { |
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.