-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Fix OAuth redirect URI format to align with Microsoft's URL standards #260446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix OAuth redirect URI format to align with Microsoft's URL standards #260446
Conversation
This change adds a trailing slash to the redirect URI returned by the loopbackServer's redirectUri getter to match the expected format for OAuth client registration. The issue occurs because Microsoft Entra ID automatically appends a trailing slash to redirect URIs without a path segment, but VS Code was returning URLs without the trailing slash, causing validation failures during OAuth authentication. Fixes microsoft#260425
| if (this._port === undefined) { | ||
| throw new Error('Server is not started yet'); | ||
| } | ||
| return `http://127.0.0.1:${this._port}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you only update this and not the redirect uris?
vscode/src/vs/base/common/oauth.ts
Lines 739 to 747 in a9c4b92
| 'http://localhost', | |
| 'http://127.0.0.1', | |
| // Added these for any server that might do | |
| // only exact match on the redirect URI even | |
| // though the spec says it should not care | |
| // about the port. | |
| `http://localhost:${DEFAULT_AUTH_FLOW_PORT}`, | |
| `http://127.0.0.1:${DEFAULT_AUTH_FLOW_PORT}` | |
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above file has not been updated in a while.
The June 29th PR that modified loopbackServer.ts, removed the trailing slash, introducing this standards compliance issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change may have affected it
a62ed27
Let me update this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have updated the PR with changes to src/vs/base/common/oauth.ts
Complements the loopbackServer.ts fix by ensuring redirect URIs used in OAuth dynamic client registration also include trailing slashes for complete standards compliance with Microsoft's OAuth 2.0 URL format. Updated redirect URIs: - http://localhost -> http://localhost/ - http://127.0.0.1 -> http://127.0.0.1/ - http://localhost:{port} -> http://localhost:{port}/ - http://127.0.0.1:{port} -> http://127.0.0.1:{port}/
TylerLeonhardt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just need you to agree to the contributor agreement and we can get this in!
|
@microsoft-github-policy-service agree |
|
Tests failing: |
|
Do you want me to open a different PR to fix the tests or update the current one itself? |
|
@bluedog13 can you update the current one please |
The fetchDynamicRegistration function correctly includes trailing slashes on redirect URIs per the implementation. This updates the test expectations to match the actual behavior, fixing the test failure. The implementation in oauth.ts includes trailing slashes on localhost URIs: - 'http://localhost/' (with trailing slash) - 'http://127.0.0.1/' (with trailing slash) - 'http://localhost:/' (with trailing slash) - 'http://127.0.0.1:/' (with trailing slash) This test was expecting URIs without trailing slashes, causing the assertion to fail. The fix aligns the test with the correct implementation behavior.
|
The tests have been updated. |
|
Thanks for contributing @bluedog13! |
|
Thank you for accepting the PR. @TylerLeonhardt |
OAuth Redirect URI Format Not Aligned with Microsoft's URL Standards
Problem
VS Code's OAuth implementation generates redirect URIs without trailing slashes, while Microsoft's own OAuth 2.0 documentation and standards-compliant identity providers (including Entra ID) require trailing slashes in redirect URIs per RFC specifications.
This creates a mismatch where:
http://127.0.0.1:3000http://127.0.0.1:3000/Root Cause
Microsoft Entra ID (and other compliant IDPs) automatically append trailing slashes to redirect URIs during OAuth flows, following Microsoft's documented standards. However, VS Code's implementation returns URLs without trailing slashes, causing URI mismatch validation failures.
Recent Change Context
A June 29th PR that modified
loopbackServer.tsremoved the trailing slash, introducing this standards compliance issue. This change made VS Code generate non-compliant redirect URIs that don't align with Microsoft's own OAuth 2.0 format requirements.Solution
This PR restores trailing slashes in two key locations:
loopbackServer.ts(line 105): Runtime redirect URI generationoauth.ts(lines 739-746): Dynamic client registration redirect URIsChanges:
http://127.0.0.1:${port}→http://127.0.0.1:${port}/http://localhost→http://localhost/http://127.0.0.1→http://127.0.0.1/http://localhost:${port}→http://localhost:${port}/Impact
Standards Reference
This change ensures VS Code follows Microsoft's own OAuth 2.0 redirect URI format requirements, improving compatibility with standards-compliant identity providers.
Fixes #260425