Skip to content

Authenticate GitHub marketplace API requests via RFC 8693 token exchange - #325815

Draft
Michael Cummings (MSFT) (mcumming) wants to merge 20 commits into
microsoft:mainfrom
mcumming:github-marketplace-api-auth
Draft

Michael Cummings (MSFT) (mcumming) wants to merge 20 commits into
microsoft:mainfrom
mcumming:github-marketplace-api-auth

Conversation

@mcumming

@mcumming Michael Cummings (MSFT) (mcumming) commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Part of #325412. This PR adds GitHub authentication for a private extension marketplace. It currently includes the shared marketplace renewal work from #343688, which remains a separate prerequisite PR; the combined diff is temporary.

Changes

  • Discover RFC 9728 protected-resource and RFC 8414 authorization-server metadata, then exchange the selected GitHub session token for a marketplace-audience token using RFC 8693. Existing SKU/enterprise eligibility checks remain in place; a marketplace without protected-resource metadata is accessed anonymously.
  • Require same-origin HTTPS for the advertised authorization server and token endpoint, and disable redirects on the token-exchange request. Shared issuer validation is opt-in for this flow and Agent Host MCP; other OAuth discovery callers remain permissive. Node/Electron redirect protection is provided by Do not forward request credentials across origins on redirects #343690.
  • Refresh GitHub marketplace tokens proactively and retry transient discovery, exchange, and service-index failures with bounded backoff. Retain the last accepted snapshot only for the same account and marketplace while its token has a known, unexpired lifetime. Retraction, sign-out, account changes, and expiry clear the prior authorization.
  • Publish token-only updates to shared and remote processes independently of manifest notifications. Structurally identical catalogs do not refresh the Extensions view; actual catalog changes still notify. The prerequisite also adds Entra resource-token renewal and authenticated rejection recovery.

Validation

  • Passed: 381 tests, using incrementally transpiled client output and the Node unit harness:

    node test\unit\node\index.js --run src\vs\workbench\services\extensionManagement\test\electron-browser\extensionGalleryManifestService.test.ts --run src\vs\platform\extensionManagement\test\common\extensionGalleryAuthorization.test.ts --run src\vs\platform\extensionManagement\test\common\extensionGalleryService.test.ts --run src\vs\platform\extensionResourceLoader\test\common\extensionResourceLoader.test.ts --run src\vs\platform\request\test\node\requestFinalUrl.test.ts --run src\vs\base\test\common\oauth.test.ts --timeout 10000
  • Passed: node .\node_modules\eslint\bin\eslint.js src\vs\workbench\services\extensionManagement\common\extensionGalleryAccount.ts src\vs\workbench\services\extensionManagement\electron-browser\extensionGalleryAccountService.ts src\vs\workbench\services\extensionManagement\electron-browser\extensionGalleryManifestService.ts src\vs\workbench\services\extensionManagement\test\electron-browser\extensionGalleryManifestService.test.ts.

  • Passed: node build\lib\formatter.ts --verify src\vs\workbench\services\extensionManagement\common\extensionGalleryAccount.ts src\vs\workbench\services\extensionManagement\electron-browser\extensionGalleryAccountService.ts src\vs\workbench\services\extensionManagement\electron-browser\extensionGalleryManifestService.ts src\vs\workbench\services\extensionManagement\test\electron-browser\extensionGalleryManifestService.test.ts.

  • Blocked: node .\node_modules\@typescript\native\bin\tsc --project .\src\tsconfig.json --noEmit --skipLibCheck reports errors in unrelated code against stale installed dependencies, including the Copilot SDK; no marketplace-file diagnostics were reported. The Node tests were not a clean build or an Electron test run.

  • Live GitHub marketplace exchange, Entra/broker behavior, actual sleep/resume, and remote deployments were not exercised.

Remaining review items

  • Review and merge Renew marketplace resource tokens before expiry #343688 separately before this PR; its shared changes are currently included here for integration.
  • Confirm the token-exchange client_id contract against a live deployment and obtain security review of distributing the marketplace bearer to the shared process and connected remote server.
  • This PR remains draft pending the requested human reviews.

Drafted with GitHub Copilot.

Copilot AI review requested due to automatic review settings July 14, 2026 15:34

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.

Pull request overview

Adds RFC 8693 GitHub token exchange for authenticated Private Marketplace deployments, alongside stacked Entra authentication groundwork.

Changes:

  • Negotiates and distributes resource-scoped marketplace tokens.
  • Attaches tokens to protected gallery and resource requests.
  • Adds provider-aware UI, policy configuration, caching, and tests.
Show a summary per file
File Description
build/lib/policies/policyData.jsonc Exports the auth-provider policy.
product.json Registers Microsoft trusted auth access.
src/vs/base/common/product.ts Adds the Entra product gate.
src/vs/platform/extensionManagement/common/extensionGalleryManifest.ts Defines auth metadata, token exchange, states, and APIs.
src/vs/platform/extensionManagement/common/extensionGalleryManifestService.ts Provides the default token implementation.
src/vs/platform/extensionManagement/common/extensionGalleryManifestServiceIpc.ts Transfers negotiated tokens over IPC.
src/vs/platform/extensionManagement/common/extensionGalleryService.ts Authenticates gallery API and asset requests.
src/vs/platform/extensionResourceLoader/common/extensionResourceLoader.ts Adds guarded resource authorization headers.
src/vs/platform/extensionResourceLoader/common/extensionResourceLoaderService.ts Authenticates native resource requests.
src/vs/platform/extensionResourceLoader/browser/extensionResourceLoaderService.ts Authenticates browser resource requests.
src/vs/workbench/contrib/extensions/common/extensions.ts Re-exports the provider context key.
src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts Adds provider-aware marketplace status UI.
src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts Registers policy and provider-routed sign-in.
src/vs/workbench/services/extensionManagement/electron-browser/extensionGalleryManifestService.ts Implements negotiation, eligibility, caching, and invalidation.
src/vs/workbench/services/extensionManagement/test/electron-browser/extensionGalleryManifestService.test.ts Tests provider and negotiation scenarios.

Review details

  • Files reviewed: 15/15 changed files
  • Comments generated: 5
  • Review effort level: Medium

@joshspicer

Copy link
Copy Markdown
Contributor

TylerLeonhardt some oauth changes here, if interested in reviewing.

@sandy081

Copy link
Copy Markdown
Member

@sandy081

Copy link
Copy Markdown
Member

Thanks for the PR - LGTM

@sandy081

Copy link
Copy Markdown
Member

Michael Cummings (MSFT) (@mcumming) Can you please update the PR by merging the main and resolving the conflicts?

@mcumming

Michael Cummings (MSFT) (mcumming) commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Compatibility with the focused post-merge fixes

Verified the unchanged GitHub feature head 524003e6751f48796de3c6fd373e99a19952a745 together with all five focused fixes in an isolated local integration branch, including the AI-review corrections. No existing feature branch was rewritten, no GitHub PR was merged, and no combined/omnibus PR was opened. This feature PR remains draft pending the requested human reviews.

Tested revisions: #343690 through 2db314a84f6b785b891f02aab29576f07ecd9b93 (full Electron URL/path and POST-to-GET header handling); #343689 at ea933051db9f4bb72f7ebb0202b4d8e16061a723 (resource-only Entra credentials); #343688 through 6169719bb89f432258772297bd9f31797ec24ccd (renewal and safe recovery); #343686 at f4ff9171ea51a9ddb59f99c15058fe08607b745e (401/403); and #343687's metadata validation at 6077a2e842f2073f645e40e8012f019ac52fdc40 plus its test-only compatibility correction now pushed as d6f7bf78d0ff7de7c9c3490da488b95ffaf2aac8.

Result: 300 selected tests passed, 0 failed. Native client compilation, changed-file hygiene, module/type layer checks, and aggregate whitespace checks also passed. The actual cache PR's corrected test file exactly matches the validated integration file, and all four final request transport/test/harness files match the redirect PR. The existing Kerberos lookup case remains excluded because its native/module dependency is unavailable; the same unrelated failure was reproduced on unmodified upstream code. This is compatibility evidence, not live deployment validation or security approval.

Exact final combined test command, from the isolated integration workspace:

$env:VSCODE_SKIP_PRELAUNCH = '1'
.\scripts\test.bat --reporter dot --run src\vs\workbench\services\extensionManagement\test\electron-browser\extensionGalleryManifestService.test.ts --run src\vs\workbench\services\extensionManagement\test\electron-browser\extensionGalleryAccountService.test.ts --run src\vs\platform\request\test\node\requestService.test.ts --run src\vs\platform\request\test\electron-main\requestService.test.ts --run src\vs\base\test\common\oauth.test.ts --grep 'WorkbenchExtensionGalleryManifestService|MicrosoftGalleryAccountProvider|OAuth|Request Service(?! Kerberos lookup)'

npm run typecheck-client and npm run valid-layers-check passed. Local integration state is preserved at 3efba3dffbdddc7b5b25ea49b7810414a5fab9ea; the scratch branch was not pushed.

Rebase notes for keeping reviews separate:

  • Keep strict resource-only selection and renewal hints together; do not restore identity-token or identity-scope fallbacks.
  • Route Microsoft's bounded cache and metadata validation through the existing shared discovery helper, passing the existing provider loggers and retaining the resource used by GitHub exchange. Do not introduce a duplicate discovery method. Renewal's current-gallery guard uses the active cache URL rather than restoring the superseded field.
  • Retain GitHub exchange/renewal and both providers' cases, deduplicate scheduler imports, and replace older generic redirect hunks with Do not forward request credentials across origins on redirects #343690's final transport implementation.
  • Cache tests project accessToken instead of snapshotting the extensible account object. Controls for omitted/empty advertised scopes check passive cache reuse, while nonempty-scope controls still assert exact interactive consent. The initial combined run of the new review fixes exposed two no-scope test assumptions about the deliberately removed identity fallback; the portable test-only correction is now in the actual cache PR, not left only in the scratch branch. No product fallback was restored.

All four outstanding AI review threads across the focused PRs have been replied to and resolved. Human approval of OAuth/renewal and Node/Electron redirects is still required, including the explicit remote credential-delegation review at #343689 (comment).

Drafted with GitHub Copilot.

@sandy081

Copy link
Copy Markdown
Member

Thanks for updating the PR. The marketplace integration looks consistent with the previous review—the existing getAccount(serviceIndexUrl) API remains the boundary, and I don’t see further structural changes needed there.

TylerLeonhardt could you review the GitHub token exchange and renewal lifecycle, particularly expiry scheduling and recovery from transient failures? A temporary renewal failure should not immediately turn an available marketplace into “Requires sign-in.”

Christof Marti (@chrmarti) could you review the request-service redirect changes, including Electron behavior? Since these affect all request-service consumers, I’d prefer landing them separately via #343690 and rebasing this PR on that fix.

@sandy081
Sandeep Somavarapu (sandy081) marked this pull request as draft October 23, 2026 12:17

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.

Approving the marketplace integration and service structure from my side. This approval does not cover the OAuth token exchange/renewal or request-service redirect behavior.

TylerLeonhardt please review the OAuth token exchange and renewal lifecycle. Christof Marti (@chrmarti) please review the Node/Electron request-service redirect changes.

I’m moving this PR to draft pending those reviews. Please mark it ready and merge only after all three of us (Sandeep Somavarapu (@sandy081), TylerLeonhardt, and Christof Marti (@chrmarti)) have approved and the outstanding concerns have been resolved.

Comment thread src/vs/base/common/oauth.ts Resolved

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.

I looked at the two new commits responding to Tyler. Moving Connor's Entra-aware comparison into the shared helper makes sense, but removing the opt-in means issuer validation now applies to every caller of fetchAuthorizationServerMetadata, not just the marketplace and Agent Host. That includes third-party MCP OAuth in extHostMcp, dynamic auth providers and XAA in mainThreadAuthentication, and extHostXaaAuthProvider.

That is a user-visible change, for MCP in particular (inline). The PR description doesn't mention it, and no test covers the affected path. Could you confirm with Tyler and Connor that enabling it for all callers is intended? If it is, I'd split it into its own PR so the MCP owners can review it and it can be reverted independently. If not, keep it opt-in for the marketplace and Agent Host.


Review assisted by Copilot.

Comment thread src/vs/base/common/oauth.ts Resolved
When a GitHub-provider marketplace is gated, discover its protected resource (RFC 9728) and
exchange the default account's GitHub session token at the marketplace's authorization server
(RFC 8693). The subject token is only sent to a same-origin HTTPS token endpoint, with redirects
disabled, and the RFC 8414 issuer is validated. Re-validate on GitHub session changes.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
…e exchanged GitHub token

The node request service now strips Authorization and Cookie when a redirect leaves the origin,
so every token-bearing marketplace request is protected. The GitHub provider re-resolves the
account before the exchanged token expires so protected requests do not start failing.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
@mariaghiondea

Copy link
Copy Markdown

TylerLeonhardt Christof Marti (@chrmarti) this is ready for your re-review 🙏

Use the authentication provider's remaining lifetime to schedule silent resource-token renewal. Coalesce account resolutions, cancel stale generations, retain available manifests during transient failures, and publish rotated process snapshots.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 859d436-9028-4925-a02c-73264226d5f8
…lures

Distinguish failed renewal of the same account and gallery from initial consent and account switches. Exercise a resource-session failure rather than an identity-session proxy, and ensure a different account cannot keep the previous bearer.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 859d436-9028-4925-a02c-73264226d5f8
Avoid introducing polling or a second renewal cadence for GitHub and other account providers. Clear retry ownership when the provider or marketplace changes, and exercise both initial failures and provider replacement.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 859d436-9028-4925-a02c-73264226d5f8
Separate marketplace credential projection from catalog notifications and recover current-bearer failures through one coalesced silent renewal path. Preserve account/cancellation guards and safe request replay.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 859d436-9028-4925-a02c-73264226d5f8
Share a one-minute completion cooldown across rejection reporters and rotating bearers. Avoid forcing the same rejected current credential twice, retain a server-accepted catalog when renewal returns an unchanged bearer, and preserve genuine authentication failure handling.

Cover remote/shared rejection loops, exact cooldown boundaries, slow and failed refreshes, normal expiry renewal, and account/session-change races.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 859d436-9028-4925-a02c-73264226d5f8
Retain the merge-only regression coverage from df60f49 in the rebased history: same-origin, cross-origin and out-and-back authorization proof, renewable-account 403 handling without forced renewal, and metadata-cache reuse during expiry renewal.

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b972512b-5cf0-4fb8-88b3-ef6b24a19441
* `chatSetupMicrosoftProbe.ts`.
*/
const WORKBENCH_INCLUDE_UNAPPROVED_ACCOUNTS = '_workbenchIncludeUnapprovedAccounts';
const WORKBENCH_FORCE_REFRESH = '_workbenchForceRefresh';

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.

Nope, do not do this. This is a hack. WORKBENCH_INCLUDE_UNAPPROVED_ACCOUNTS was only for a specific scenario and temporary. We do not wanna depend on private contracts between Core and the Extension.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, agreed. The private refresh contract is now removed from both branches. Token renewal is handled inside the auth extension.

Changes

  • Renew marketplace resource tokens before expiry #343688 (dev/mcumming/marketplace-auth-follow-ups): 0699fc5

  • This PR (github-marketplace-api-auth): 9900923 (same change, synced)

  • Removed _workbenchForceRefresh / WORKBENCH_FORCE_REFRESH from authProvider.ts, authentication.ts, and the gallery account service and provider. authProvider.ts now matches main.

  • CachedPublicClientApplication now refreshes on its own. If MSAL returns a cached access token that expires within 5 minutes (new isAccessTokenNearExpiry helper in src/common/tokenExpiry.ts), it forces a silent refresh through the existing sequencer. With the broker this uses the claims request; otherwise it uses forceRefresh: true. If that refresh fails, it keeps the cached token while it is still unexpired and rethrows once it has expired. The workbench now gets fresh tokens through the public getSession path with no special options.

WORKBENCH_INCLUDE_UNAPPROVED_ACCOUNTS
I left it alone. It is not part of this PR: it is already on main from #338823 and used by the chat-setup Microsoft probe (chatSetupMicrosoftProbe.ts). Removing it would break that feature, so it should be handled separately with the chat-setup owners.

Tradeoff
Without a forced-refresh option, a 401 on a token that was revoked but hasn't expired can no longer force a silent refresh. The 401 retry still asks again, but it may get the same cached token, and then the existing cooldown applies. It recovers once the token is near expiry, or after the user signs out and back in. If faster 401 recovery is needed, I think a public challenge-based API is the right route, not another sentinel.

Validation (run locally on 9900923)

  • build-fast --client-only passed.
  • extensionGalleryManifestService.test.ts + extensionGalleryAccountService.test.ts: 278 passing.
  • typecheck-client and the extension tsc --noEmit both exited 0.
  • eslint on the changed files exited 0.
  • compile-extension:microsoft-authentication finished with 0 errors.
  • The tokenExpiry mocha test passed (1 test).
  • I did not exercise live sign-in or the broker flow.

This reply was drafted by an AI agent (GitHub Copilot) on behalf of Michael Cummings (MSFT) (@mcumming).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

VSPM has decided CAE and claims challenges are non-goals. Revoked-token recovery relies on the server's planned invalid_token response and near-expiry renewal of short-lived non-CAE tokens. In #343688, if silent resolution returns the rejected token, sign-in is required; insufficient_claims is only a defensive sign-in fallback. Neither a cache bypass nor a public forceRefresh API is planned.

This reply was drafted by an AI agent (GitHub Copilot) on behalf of Michael Cummings (MSFT) (@mcumming).

…orkbench sentinel

Remove the private _workbenchForceRefresh / WORKBENCH_FORCE_REFRESH contract between the workbench and the microsoft-authentication extension. The extension now forces a silent refresh itself when a cached access token is within five minutes of expiry, falling back to the cached token if the refresh fails before expiry. Mirrors the change on dev/mcumming/marketplace-auth-follow-ups.

Co-authored-by: Copilot App <[email protected]>

This branch has not been deployed

No deployments
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.

8 participants