Skip to content

Fallback to .well-known/oauth-protected-resource on 401s without WWW-Authenticate#268977

Merged
TylerLeonhardt merged 3 commits intomainfrom
tyler/specified-iguana
Sep 30, 2025
Merged

Fallback to .well-known/oauth-protected-resource on 401s without WWW-Authenticate#268977
TylerLeonhardt merged 3 commits intomainfrom
tyler/specified-iguana

Conversation

@TylerLeonhardt
Copy link
Copy Markdown
Member

@TylerLeonhardt TylerLeonhardt commented Sep 29, 2025

Fixes #268210

the logic is going to get more complicated, so I want to encapsulate it where it should go.
Copilot AI review requested due to automatic review settings September 29, 2025 23:37
@TylerLeonhardt TylerLeonhardt enabled auto-merge (squash) September 29, 2025 23:37
@TylerLeonhardt TylerLeonhardt self-assigned this Sep 29, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors OAuth protected resource metadata fetching logic by extracting it from the MCP HTTP client into a reusable function in the OAuth base module. The change encapsulates the resource metadata retrieval logic in preparation for increased complexity.

Key Changes

  • Created a new fetchResourceMetadata function in the OAuth base module with proper validation and origin-based header handling
  • Replaced the private _getResourceMetadata method in McpHTTPHandle with a call to the new centralized function
  • Added comprehensive test coverage for the new function including edge cases and error scenarios

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/vs/base/common/oauth.ts Added fetchResourceMetadata function with origin detection, validation, and error handling
src/vs/workbench/api/common/extHostMcp.ts Replaced private method with call to new centralized function and removed duplicate logic
src/vs/base/test/common/oauth.test.ts Added comprehensive test suite covering success cases, error handling, and edge cases

Comment thread src/vs/base/common/oauth.ts Outdated
try {
errorText = await response.text();
} catch {
errorText = 'statusText' in response ? response.statusText : 'Unknown error';
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The fallback logic assumes that response might have a statusText property, but the CommonResponse interface doesn't include this property. Consider using a more specific fallback or updating the interface to include statusText if it's expected to be available.

Suggested change
errorText = 'statusText' in response ? response.statusText : 'Unknown error';
errorText = 'Unknown error';

Copilot uses AI. Check for mistakes.
Comment thread src/vs/base/test/common/oauth.test.ts
@vs-code-engineering vs-code-engineering Bot added this to the September 2025 milestone Sep 29, 2025
dmitrivMS
dmitrivMS previously approved these changes Sep 29, 2025
@TylerLeonhardt TylerLeonhardt changed the title refactor resource metadata reading into oauth base file Fallback to .well-known/oauth-protected-resource on 401s without WWW-Authenticate Sep 30, 2025
@TylerLeonhardt TylerLeonhardt merged commit 50e37a4 into main Sep 30, 2025
28 checks passed
@TylerLeonhardt TylerLeonhardt deleted the tyler/specified-iguana branch September 30, 2025 05:31
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fallback to .well-known/oauth-protected-resource on 401s without WWW-Authenticate

4 participants