Skip to content

Commit 914c571

Browse files
akosyakovjeanp413
authored andcommitted
fix JWT token parsing
1 parent 94cc6fc commit 914c571

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

extensions/gitpod/src/auth.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const newConfig = {
136136
canSwitch: true,
137137
authenticationProviders: {
138138
gitpod: {
139-
scopes: [...gitpodScopes]
139+
scopes: ['function:accessCodeSyncStorage']
140140
}
141141
}
142142
};
@@ -316,11 +316,10 @@ export async function resolveAuthenticationSession(scopes: readonly string[], co
316316

317317
const exchangeTokenData: ExchangeTokenResponse = await exchangeTokenResponse.json();
318318
console.log(exchangeTokenData);
319-
const access_token = exchangeTokenData.access_token;
319+
const jwtToken = exchangeTokenData.access_token;
320+
const accessToken = JSON.parse(Buffer.from(jwtToken.split('.')[1], 'base64').toString())['jti'];
320321

321-
console.log(access_token);
322-
323-
const { gitpodService, pendignWebSocket } = await createApiWebSocket(access_token);
322+
const { gitpodService, pendignWebSocket } = await createApiWebSocket(accessToken);
324323
const user = await gitpodService.server.getLoggedInUser();
325324
(await pendignWebSocket).close();
326325
return {
@@ -329,8 +328,8 @@ export async function resolveAuthenticationSession(scopes: readonly string[], co
329328
label: user.name!,
330329
id: user.id
331330
},
332-
scopes: scopes,
333-
accessToken: access_token
331+
scopes,
332+
accessToken
334333
};
335334
} catch (e) {
336335
vscode.window.showErrorMessage(`Couldn't connect: ${e}`);
@@ -405,8 +404,8 @@ async function askToEnable(context: vscode.ExtensionContext): Promise<void> {
405404
*/
406405
export async function createSession(scopes: readonly string[], context: vscode.ExtensionContext): Promise<vscode.AuthenticationSession> {
407406
const callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://gitpod.gitpod-desktop/complete-gitpod-auth`));
408-
if (![...gitpodScopes].every((scope) => scopes.includes(scope))) {
409-
vscode.window.showErrorMessage('The provided scopes are not enough to turn on Settings Sync');
407+
if (scopes.some(scope => !gitpodScopes.has(scope))) {
408+
throw new Error('invalid scopes');
410409
}
411410

412411
const gitpodAuth = await createOauth2URL(context, {

0 commit comments

Comments
 (0)