From 32f934cebee50ef587155a91dbb0c67cc9f7d48d Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Wed, 2 Sep 2020 12:39:19 +0200 Subject: [PATCH] Pass credentials through args --- resources/web/code-web.js | 33 +++++++++++++++++-- .../code/browser/workbench/workbench-dev.html | 3 ++ src/vs/code/browser/workbench/workbench.ts | 14 +++++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/resources/web/code-web.js b/resources/web/code-web.js index 1185eedcfbc..16f1d3d93cd 100644 --- a/resources/web/code-web.js +++ b/resources/web/code-web.js @@ -18,6 +18,7 @@ const fancyLog = require('fancy-log'); const ansiColors = require('ansi-colors'); const remote = require('gulp-remote-retry-src'); const vfs = require('vinyl-fs'); +const uuid = require('uuid'); const extensions = require('../../build/lib/extensions'); @@ -34,14 +35,16 @@ const args = minimist(process.argv, { 'no-launch', 'help', 'verbose', - 'wrap-iframe' + 'wrap-iframe', + 'enable-sync' ], string: [ 'scheme', 'host', 'port', 'local_port', - 'extension' + 'extension', + 'github-auth' ], }); @@ -50,11 +53,13 @@ if (args.help) { 'yarn web [options]\n' + ' --no-launch Do not open VSCode web in the browser\n' + ' --wrap-iframe Wrap the Web Worker Extension Host in an iframe\n' + + ' --enable-sync Enable sync by default\n' + ' --scheme Protocol (https or http)\n' + ' --host Remote host\n' + ' --port Remote/Local port\n' + ' --local_port Local port override\n' + ' --extension Path of an extension to include\n' + + ' --github-auth Github authentication token\n' + ' --verbose Print out more information\n' + ' --help\n' + '[Example]\n' + @@ -356,14 +361,38 @@ async function handleRoot(req, res) { const webConfigJSON = { folderUri: folderUri, staticExtensions, + enableSyncByDefault: args['enable-sync'], }; if (args['wrap-iframe']) { webConfigJSON._wrapWebWorkerExtHostInIframe = true; } + const credentials = []; + if (args['github-auth']) { + const sessionId = uuid.v4(); + credentials.push({ + service: 'code-oss.login', + account: 'account', + password: JSON.stringify({ + id: sessionId, + providerId: 'github', + accessToken: args['github-auth'] + }) + }, { + service: 'code-oss-github.login', + account: 'account', + password: JSON.stringify([{ + id: sessionId, + scopes: ['user:email'], + accessToken: args['github-auth'] + }]) + }); + } + const data = (await readFile(WEB_MAIN)).toString() .replace('{{WORKBENCH_WEB_CONFIGURATION}}', () => escapeAttribute(JSON.stringify(webConfigJSON))) // use a replace function to avoid that regexp replace patterns ($&, $0, ...) are applied .replace('{{WORKBENCH_BUILTIN_EXTENSIONS}}', () => escapeAttribute(JSON.stringify(dedupedBuiltInExtensions))) + .replace('{{WORKBENCH_CREDENTIALS}}', () => escapeAttribute(JSON.stringify(credentials))) .replace('{{WEBVIEW_ENDPOINT}}', '') .replace('{{REMOTE_USER_DATA_URI}}', ''); diff --git a/src/vs/code/browser/workbench/workbench-dev.html b/src/vs/code/browser/workbench/workbench-dev.html index 55ae7a39871..25e7b05fe16 100644 --- a/src/vs/code/browser/workbench/workbench-dev.html +++ b/src/vs/code/browser/workbench/workbench-dev.html @@ -17,6 +17,9 @@ + + + diff --git a/src/vs/code/browser/workbench/workbench.ts b/src/vs/code/browser/workbench/workbench.ts index fccfbe81032..6cd3fa05be5 100644 --- a/src/vs/code/browser/workbench/workbench.ts +++ b/src/vs/code/browser/workbench/workbench.ts @@ -27,6 +27,13 @@ class LocalStorageCredentialsProvider implements ICredentialsProvider { static readonly CREDENTIALS_OPENED_KEY = 'credentials.provider'; + constructor(credentials: ICredential[]) { + this._credentials = credentials; + for (const { service, account, password } of this._credentials) { + this.setPassword(service, account, password); + } + } + private _credentials: ICredential[] | undefined; private get credentials(): ICredential[] { if (!this._credentials) { @@ -430,6 +437,11 @@ class WindowIndicator implements IWindowIndicator { window.location.href = `${window.location.origin}?${queryString}`; }; + // Find credentials from DOM + const credentialsElement = document.getElementById('vscode-workbench-credentials'); + const credentialsElementAttribute = credentialsElement ? credentialsElement.getAttribute('data-settings') : undefined; + const credentialsProvider = new LocalStorageCredentialsProvider(credentialsElementAttribute ? JSON.parse(credentialsElementAttribute) : []); + // Finally create workbench create(document.body, { ...config, @@ -438,6 +450,6 @@ class WindowIndicator implements IWindowIndicator { productQualityChangeHandler, workspaceProvider, urlCallbackProvider: new PollingURLCallbackProvider(), - credentialsProvider: new LocalStorageCredentialsProvider() + credentialsProvider }); })();