Skip to content

Commit 1b56299

Browse files
fix: conditionally append scope parameter in authorization URL for DynamicAuthProvider (microsoft#250084)
* fix: conditionally append scope parameter in authorization URL for DynamicAuthProvider * Apply change to all flows --------- Co-authored-by: Tyler Leonhardt <[email protected]>
1 parent 7de0f0e commit 1b56299

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/vs/workbench/api/common/extHostAuthentication.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,17 @@ export class DynamicAuthProvider implements vscode.AuthenticationProvider {
422422
}
423423

424424
// Prepare the authorization request URL
425-
const scopeString = scopes.join(' ');
426425
const authorizationUrl = new URL(this._serverMetadata.authorization_endpoint!);
427426
authorizationUrl.searchParams.append('client_id', this.clientId);
428427
authorizationUrl.searchParams.append('response_type', 'code');
429-
authorizationUrl.searchParams.append('scope', scopeString);
430428
authorizationUrl.searchParams.append('state', state.toString());
431429
authorizationUrl.searchParams.append('code_challenge', codeChallenge);
432430
authorizationUrl.searchParams.append('code_challenge_method', 'S256');
431+
const scopeString = scopes.join(' ');
432+
if (scopeString) {
433+
// If non-empty scopes are provided, include scope parameter in the request
434+
authorizationUrl.searchParams.append('scope', scopeString);
435+
}
433436
if (this._resourceMetadata?.resource) {
434437
// If a resource is specified, include it in the request
435438
authorizationUrl.searchParams.append('resource', this._resourceMetadata.resource);

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,15 @@ export class NodeDynamicAuthProvider extends DynamicAuthProvider {
242242
const codeChallenge = await this.generateCodeChallenge(codeVerifier);
243243

244244
// Prepare the authorization request URL
245-
const scopeString = scopes.join(' ');
246245
const authorizationUrl = new URL(this._serverMetadata.authorization_endpoint!);
247246
authorizationUrl.searchParams.append('client_id', this.clientId);
248247
authorizationUrl.searchParams.append('response_type', 'code');
249-
authorizationUrl.searchParams.append('scope', scopeString);
250248
authorizationUrl.searchParams.append('code_challenge', codeChallenge);
251249
authorizationUrl.searchParams.append('code_challenge_method', 'S256');
250+
const scopeString = scopes.join(' ');
251+
if (scopeString) {
252+
authorizationUrl.searchParams.append('scope', scopeString);
253+
}
252254
if (this._resourceMetadata?.resource) {
253255
// If a resource is specified, include it in the request
254256
authorizationUrl.searchParams.append('resource', this._resourceMetadata.resource);
@@ -321,7 +323,13 @@ export class NodeDynamicAuthProvider extends DynamicAuthProvider {
321323
// Step 1: Request device and user codes
322324
const deviceCodeRequest = new URLSearchParams();
323325
deviceCodeRequest.append('client_id', this.clientId);
324-
deviceCodeRequest.append('scope', scopeString);
326+
if (scopeString) {
327+
deviceCodeRequest.append('scope', scopeString);
328+
}
329+
if (this._resourceMetadata?.resource) {
330+
// If a resource is specified, include it in the request
331+
deviceCodeRequest.append('resource', this._resourceMetadata.resource);
332+
}
325333

326334
let deviceCodeResponse: Response;
327335
try {

0 commit comments

Comments
 (0)