Skip to content

Commit 21220fc

Browse files
committed
Add Gitpod to Settings sync
1 parent cddd312 commit 21220fc

File tree

7 files changed

+505
-102
lines changed

7 files changed

+505
-102
lines changed

extensions/gitpod/extension-browser.webpack.config.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

extensions/gitpod/package.json

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "%displayName%",
44
"description": "%description%",
55
"publisher": "gitpod",
6-
"version": "0.0.25",
6+
"version": "0.0.28",
77
"license": "MIT",
88
"preview": true,
99
"icon": "resources/gitpod.png",
@@ -27,17 +27,39 @@
2727
"activationEvents": [
2828
"*",
2929
"onCommand:gitpod.api.autoTunnel",
30-
"onCommand:gitpod.api.auth"
30+
"onCommand:gitpod.api.auth",
31+
"onAuthenticationRequest:gitpod"
3132
],
3233
"contributes": {
34+
"authentication": [
35+
{
36+
"label": "Gitpod",
37+
"id": "gitpod"
38+
}
39+
],
40+
"configuration": {
41+
"title": "Settings sync",
42+
"properties": {
43+
"configurationSync.store": {
44+
"type": "object"
45+
}
46+
}
47+
},
3348
"commands": [
3449
{
35-
"command": "gitpod.api.auth",
36-
"title": "Authenthicate with GitPod"
50+
"command": "gitpod.auth.remove",
51+
"category": "Gitpod",
52+
"enablement": "gitpod.addedSyncProvider",
53+
"title": "Turn off Settings Sync"
54+
},
55+
{
56+
"command": "gitpod.auth.add",
57+
"category": "Gitpod",
58+
"enablement": "!gitpod.addedSyncProvider",
59+
"title": "Turn on Settings Sync"
3760
}
3861
]
3962
},
40-
"browser": "./out/browser/extension.js",
4163
"main": "./out/extension.js",
4264
"scripts": {
4365
"compile": "gulp compile-extension:gitpod",
@@ -50,9 +72,11 @@
5072
"@types/tmp": "^0.2.1"
5173
},
5274
"dependencies": {
75+
"@gitpod/gitpod-protocol": "main",
5376
"@gitpod/local-app-api-grpcweb": "main",
5477
"@improbable-eng/grpc-web-node-http-transport": "^0.14.0",
5578
"node-fetch": "^2.6.1",
79+
"pkce": "^1.0.0-beta2",
5680
"tmp": "^0.2.1",
5781
"vscode-nls": "^5.0.0"
5882
},

extensions/gitpod/src/browser/extension.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

extensions/gitpod/src/extension.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import * as tmp from 'tmp';
1616
import * as path from 'path';
1717
import * as vscode from 'vscode';
1818
import { grpc } from '@improbable-eng/grpc-web';
19+
import { URLSearchParams } from 'url';
20+
21+
import { registerAuth, authCompletePath, resolveAuthenticationSession, gitpodScopes } from './registerAuth';
1922

2023
interface SSHConnectionParams {
2124
workspaceId: string
@@ -48,6 +51,8 @@ export async function activate(context: vscode.ExtensionContext) {
4851
output.appendLine(`[${new Date().toLocaleString()}] ${value}`);
4952
}
5053

54+
registerAuth(context, log);
55+
5156
// TODO(ak) commands to show logs and stop local apps
5257
// TODO(ak) auto stop local apps if not used for 3 hours
5358

@@ -376,12 +381,26 @@ export async function activate(context: vscode.ExtensionContext) {
376381
}
377382
}
378383

379-
const authCompletePath = '/auth-complete';
380384
context.subscriptions.push(vscode.window.registerUriHandler({
381385
handleUri: async uri => {
382386
if (uri.path === authCompletePath) {
383387
log('auth completed');
384388
return;
389+
} else if (uri.path === '/complete-gitpod-auth') {
390+
// Get the token from the URI
391+
const token = new URLSearchParams(uri.query).get('code');
392+
if (token !== null) {
393+
const authSession = await resolveAuthenticationSession([...gitpodScopes], token);
394+
const storedValue: vscode.AuthenticationSession = authSession;
395+
const existingSessionsJSON = await context.secrets.get('gitpod.authSessions') || '[]';
396+
const existingSessions: vscode.AuthenticationSession[] = JSON.parse(existingSessionsJSON);
397+
existingSessions.push(storedValue);
398+
await context.secrets.store('gitpod.authSessions', JSON.stringify(existingSessions));
399+
log('auth completed');
400+
} else {
401+
vscode.window.showErrorMessage('Auth failed: missing token');
402+
}
403+
return;
385404
}
386405
log('open workspace window: ' + uri.toString());
387406
const params: SSHConnectionParams = JSON.parse(uri.query);

0 commit comments

Comments
 (0)