Skip to content

Commit 8065598

Browse files
Fix OAuth redirect URI format to align with Microsoft's URL standards (#260446)
* Fix OAuth redirect URI validation by adding trailing slash 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 #260425 * Add trailing slashes to OAuth redirect URIs in dynamic registration 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}/ * Fix OAuth redirect URI test expectations to match implementation 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. --------- Co-authored-by: Gautam <[email protected]> Co-authored-by: bluedog13 <>
1 parent a8313d4 commit 8065598

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/vs/base/common/oauth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,14 +736,14 @@ export async function fetchDynamicRegistration(serverMetadata: IAuthorizationSer
736736
redirect_uris: [
737737
'https://insiders.vscode.dev/redirect',
738738
'https://vscode.dev/redirect',
739-
'http://localhost',
740-
'http://127.0.0.1',
739+
'http://localhost/',
740+
'http://127.0.0.1/',
741741
// Added these for any server that might do
742742
// only exact match on the redirect URI even
743743
// though the spec says it should not care
744744
// about the port.
745-
`http://localhost:${DEFAULT_AUTH_FLOW_PORT}`,
746-
`http://127.0.0.1:${DEFAULT_AUTH_FLOW_PORT}`
745+
`http://localhost:${DEFAULT_AUTH_FLOW_PORT}/`,
746+
`http://127.0.0.1:${DEFAULT_AUTH_FLOW_PORT}/`
747747
],
748748
scope: scopes?.join(AUTH_SCOPE_SEPARATOR),
749749
token_endpoint_auth_method: 'none',

src/vs/base/test/common/oauth.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,10 @@ suite('OAuth', () => {
358358
assert.deepStrictEqual(requestBody.redirect_uris, [
359359
'https://insiders.vscode.dev/redirect',
360360
'https://vscode.dev/redirect',
361-
'http://localhost',
362-
'http://127.0.0.1',
363-
`http://localhost:${DEFAULT_AUTH_FLOW_PORT}`,
364-
`http://127.0.0.1:${DEFAULT_AUTH_FLOW_PORT}`
361+
'http://localhost/',
362+
'http://127.0.0.1/',
363+
`http://localhost:${DEFAULT_AUTH_FLOW_PORT}/`,
364+
`http://127.0.0.1:${DEFAULT_AUTH_FLOW_PORT}/`
365365
]);
366366

367367
// Verify response is processed correctly

src/vs/workbench/api/node/loopbackServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class LoopbackAuthServer implements ILoopbackServer {
102102
if (this._port === undefined) {
103103
throw new Error('Server is not started yet');
104104
}
105-
return `http://127.0.0.1:${this._port}`;
105+
return `http://127.0.0.1:${this._port}/`;
106106
}
107107

108108
private _sendPage(res: http.ServerResponse): void {

0 commit comments

Comments
 (0)