Repository navigation
auth: request refreshable OAuth tokens at sign-in [8/10] - #22943
Conversation
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The authentication and credential-lifecycle changes require the outstanding live OAuth and secure-storage validation.
Review effort: Balanced
Findings: None
What changed in this PR
Adds refreshable OAuth sign-in behind the development/preview feature flag while preserving production scopes.
Changes:
- Requests
offline_accessfor GitHub.com and GHE.com. - Persists refreshable credentials before reporting authentication success.
- Handles cancellation, duplicate callbacks, cleanup, and failure scenarios.
| File | Description |
|---|---|
app/src/lib/api.ts |
Adds conditional OAuth scope and new-authorization handling. |
app/src/lib/feature-flag.ts |
Introduces the short-lived-token feature flag. |
app/src/lib/stores/sign-in-store.ts |
Coordinates token exchange, persistence, and cleanup. |
app/src/lib/stores/app-store.ts |
Removes duplicate account persistence responsibility. |
app/test/unit/oauth-authentication-test.ts |
Adds OAuth integration and lifecycle coverage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
8a1fd5b to
7ea5ee3
Compare
7ea5ee3 to
07e3b4c
Compare
07e3b4c to
7863294
Compare
niik
left a comment
There was a problem hiding this comment.
The feature-flagged activation path is carefully structured and very well covered: duplicate/stale callbacks are rejected, issued-but-uninstalled credentials are revoked, success waits for secure credential persistence, GHES scope behavior remains compatible, and refresh secrets stay out of public state.
We reviewed the edge case where a metadata/localStorage or synchronous listener failure occurs after secure credential installation and could lead cleanup to revoke an installed token. Given the very small account metadata footprint and our expectation that localStorage is reliable here, we consider that residual risk acceptable rather than blocking.
e0b48e1 to
35d7684
Compare
This is the change that makes Desktop create short-lived, refreshable credentials. Earlier changes taught AccountsStore to store, renew and revoke them, and taught the API client, Git, private images and Copilot to use them. It is gated by `enableShortLivedTokens` (development and preview builds only), so production sign-in is unchanged. With the flag on, the OAuth authorization URL for github.com and GHE.com (data residency) adds the `offline_access` scope, which asks GitHub for an expiring access token plus a refresh token. GitHub Enterprise Server never gets the scope, and the other scopes are kept as they are. SignInStore now completes the browser sign-in itself: - it exchanges the code with `exchangeOAuthToken` against the HTML endpoint, keeping the refresh token and both expiry times, and replaces api.ts's `requestOAuthToken`; - it fetches the user with `fetchUser(..., isNewAuthorization = true)`, so the new token is used as-is instead of going through AccountsStore's token resolution and invalidation meant for installed accounts; - it saves the account and full credential with `AccountsStore.addAccount`, and only reports success after the credential is saved. If saving fails, sign-in reports an error instead of pretending to succeed; - it ignores a duplicate callback for the same OAuth state while one is being handled, and checks that the sign-in attempt is still the current one after the exchange, after fetching the user and after saving; - it revokes, in the background and without waiting, a token that was issued but never installed: the user cancelled or restarted before it was saved, or fetching the user failed. A token whose save has started is kept, as in development, where saving always completes. AppStore no longer adds the account itself when sign-in succeeds; it only logs and starts loading repositories for the welcome flow. Tests cover the OAuth scopes per host and flag value, the exchange metadata, success only after saving without exposing refresh tokens in public state, storage failures, duplicate callbacks, cancellation at each step, revocation of abandoned tokens (bounded, without blocking the result), and mismatched OAuth state. Co-authored-by: Copilot <[email protected]>
35d7684 to
fbb0c1a
Compare
|
Diyar pala |
Fixes #23173 |
Description
Turns the feature on, behind
enableShortLivedTokens(development and preview builds only). Production sign-in is unchanged.offline_access. GHES never gets it.exchangeOAuthToken, which replacesrequestOAuthToken, and keeps the refresh token and expiry times.fetchUser(..., isNewAuthorization = true), so the new token isn't treated as an installed account's token.AccountsStore.addAccountand only reports success after saving. A failed save shows an error.Stack
Merge in order, starting with 1. Each PR builds, passes tests, and keeps production behavior on its own.
Validation
Release notes
Notes: no-notes