Skip to content

Commit 8ac035c

Browse files
filiptronicekakosyakov
authored andcommitted
Fix code exchange bad request
1 parent 0c2e5bf commit 8ac035c

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

extensions/gitpod/src/auth.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,11 @@ async function createApiWebSocket(accessToken: string): Promise<{ gitpodService:
252252
}
253253
}
254254
const webSocketMaxRetries = 3;
255+
console.log(`Endpoint: ${getBaseURL().replace('https', 'wss')}`);
255256
const webSocket = new ReconnectingWebSocket(getBaseURL().replace('https', 'wss'), undefined, {
256257
minReconnectionDelay: 1000,
257258
connectionTimeout: 10000,
258-
maxRetries: webSocketMaxRetries,
259+
maxRetries: webSocketMaxRetries - 1,
259260
debug: false,
260261
startClosed: false,
261262
WebSocket: GitpodServerWebSocket
@@ -295,29 +296,21 @@ interface ExchangeTokenResponse {
295296
* @returns a promise that resolves with the authentication session
296297
*/
297298
export async function resolveAuthenticationSession(scopes: readonly string[], code: string, context: vscode.ExtensionContext): Promise<vscode.AuthenticationSession | null> {
298-
299+
const callbackUri = (await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://gitpod.gitpod-desktop/complete-gitpod-auth`))).toString(true);
299300
try {
300-
console.log('Making token request with ');
301-
console.log(new URLSearchParams({
302-
code,
303-
grant_type: 'authorization_code',
304-
client_id: `${vscode.env.uriScheme}-gitpod`,
305-
redirect_uri: 'vscode://gitpod.gitpod-desktop/complete-gitpod-auth',
306-
code_verifier: await context.secrets.get('gitpod.code_verifier')
307-
}));
308301
const exchangeTokenResponse = await fetch(`${getBaseURL()}/api/oauth/token`, {
309302
method: 'POST',
310303
body: new URLSearchParams({
311304
code,
312305
grant_type: 'authorization_code',
313306
client_id: `${vscode.env.uriScheme}-gitpod`,
314-
redirect_uri: 'vscode://gitpod.gitpod-desktop/complete-gitpod-auth',
307+
redirect_uri: callbackUri,
315308
code_verifier: await context.secrets.get('gitpod.code_verifier')
316309
})
317310
});
318311

319312
if (!exchangeTokenResponse.ok) {
320-
vscode.window.showErrorMessage(`Couldn't connect: ${exchangeTokenResponse.statusText}`);
313+
vscode.window.showErrorMessage(`Couldn't connect: ${exchangeTokenResponse.statusText}, ${await exchangeTokenResponse.text()}`);
321314
return null;
322315
}
323316

0 commit comments

Comments
 (0)