Skip to content

auth: request refreshable OAuth tokens at sign-in [8/10] - #22943

Merged
sergiou87 merged 1 commit into
developmentfrom
short-lived-tokens-8-sign-in
Oct 7, 2026
Merged

sergiou87 merged 1 commit into
developmentfrom
short-lived-tokens-8-sign-in

Conversation

@sergiou87

@sergiou87 sergiou87 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Description

Turns the feature on, behind enableShortLivedTokens (development and preview builds only). Production sign-in is unchanged.

  • For github.com and GHE.com, the authorization URL adds offline_access. GHES never gets it.
  • SignInStore exchanges the code with exchangeOAuthToken, which replaces requestOAuthToken, and keeps the refresh token and expiry times.
  • It fetches the user with fetchUser(..., isNewAuthorization = true), so the new token isn't treated as an installed account's token.
  • It saves the credential through AccountsStore.addAccount and only reports success after saving. A failed save shows an error.
  • It ignores duplicate callbacks, and checks the sign-in attempt is still current after each step.
  • It revokes, in the background, a token that was never installed (cancelled, restarted, or the user fetch failed). A token whose save already began is kept, like development.
  • AppStore no longer adds the account itself; it only starts loading repositories for the welcome flow.

Stack

Merge in order, starting with 1. Each PR builds, passes tests, and keeps production behavior on its own.

  1. auth: add OAuth refresh-token protocol primitives [1/10] #22917 - OAuth protocol primitives
  2. auth: handle rejected API tokens in AccountsStore [2/10] #22937 - Token invalidation in AccountsStore
  3. auth: add versioned secure-storage format for credentials [3/10] #22938 - Versioned credential storage
  4. auth: coordinate OAuth token renewal in AccountsStore [4/10] #22939 - Coordinated token renewal
  5. auth: hand Git fresh credentials [5/10] #22940 - Git credentials
  6. auth: resolve private image tokens through the renderer [6/10] #22941 - Private images
  7. auth: let Copilot sessions renew GitHub tokens [7/10] #22942 - Copilot SDK sessions
  8. auth: request refreshable OAuth tokens at sign-in [8/10] #22943 - Sign-in with refreshable tokens (behind flag) (this PR)
  9. docs: describe refresh-token rollout and recovery [9/10] #22919 - Rollout and recovery documentation
  10. auth: log automatic sign-outs [10/10] #22959 - Log automatic sign-outs

Validation

  • tsc and lint pass.
  • Full suite: 2,026 pass, one skipped, same four Git failures.
  • Live OAuth, Windows secure storage, Git/LFS and Copilot SDK renewal still need manual testing before rollout.

Release notes

Notes: no-notes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_access for 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.

@sergiou87
sergiou87 marked this pull request as ready for review September 28, 2026 15:58
@sergiou87
sergiou87 requested a review from a team as a code owner September 28, 2026 15:58
@sergiou87
sergiou87 requested a review from niik September 28, 2026 15:58
@sergiou87
sergiou87 force-pushed the short-lived-tokens-8-sign-in branch from 8a1fd5b to 7ea5ee3 Compare October 2, 2026 11:28
@sergiou87
sergiou87 force-pushed the short-lived-tokens-8-sign-in branch from 7ea5ee3 to 07e3b4c Compare October 2, 2026 11:42
@sergiou87 sergiou87 changed the title auth: request refreshable OAuth tokens at sign-in [8/9] auth: request refreshable OAuth tokens at sign-in [8/10] Oct 2, 2026
@sergiou87
sergiou87 force-pushed the short-lived-tokens-8-sign-in branch from 07e3b4c to 7863294 Compare October 2, 2026 12:18
niik
niik previously approved these changes Oct 2, 2026

@niik niik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sergiou87
sergiou87 force-pushed the short-lived-tokens-8-sign-in branch 3 times, most recently from e0b48e1 to 35d7684 Compare October 7, 2026 12:55
Base automatically changed from short-lived-tokens-7-copilot to development October 7, 2026 13:16
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]>
@sergiou87
sergiou87 force-pushed the short-lived-tokens-8-sign-in branch from 35d7684 to fbb0c1a Compare October 7, 2026 13:16
@sergiou87
sergiou87 merged commit ca4d0aa into development Oct 7, 2026
9 checks passed
@sergiou87
sergiou87 deleted the short-lived-tokens-8-sign-in branch October 7, 2026 14:56
Copilot AI mentioned this pull request Oct 13, 2026
3 tasks done
@vvvkkkjaan823587

Copy link
Copy Markdown

#22917
Uploading file_00000000a5a48211a40817c24f258174.png…

@diyardemir830-arch

Copy link
Copy Markdown

Diyar pala

@diyardemir830-arch

Copy link
Copy Markdown

@linthuaung1351-oss linthuaung1351-oss left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #23170

@linthuaung1351-oss linthuaung1351-oss left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#/

@linthuaung1351-oss

Copy link
Copy Markdown

#/

Fixes #23173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants