Skip to content

Commit 32f934c

Browse files
committed
Pass credentials through args
1 parent 5dc43b2 commit 32f934c

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

resources/web/code-web.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const fancyLog = require('fancy-log');
1818
const ansiColors = require('ansi-colors');
1919
const remote = require('gulp-remote-retry-src');
2020
const vfs = require('vinyl-fs');
21+
const uuid = require('uuid');
2122

2223
const extensions = require('../../build/lib/extensions');
2324

@@ -34,14 +35,16 @@ const args = minimist(process.argv, {
3435
'no-launch',
3536
'help',
3637
'verbose',
37-
'wrap-iframe'
38+
'wrap-iframe',
39+
'enable-sync'
3840
],
3941
string: [
4042
'scheme',
4143
'host',
4244
'port',
4345
'local_port',
44-
'extension'
46+
'extension',
47+
'github-auth'
4548
],
4649
});
4750

@@ -50,11 +53,13 @@ if (args.help) {
5053
'yarn web [options]\n' +
5154
' --no-launch Do not open VSCode web in the browser\n' +
5255
' --wrap-iframe Wrap the Web Worker Extension Host in an iframe\n' +
56+
' --enable-sync Enable sync by default\n' +
5357
' --scheme Protocol (https or http)\n' +
5458
' --host Remote host\n' +
5559
' --port Remote/Local port\n' +
5660
' --local_port Local port override\n' +
5761
' --extension Path of an extension to include\n' +
62+
' --github-auth Github authentication token\n' +
5863
' --verbose Print out more information\n' +
5964
' --help\n' +
6065
'[Example]\n' +
@@ -356,14 +361,38 @@ async function handleRoot(req, res) {
356361
const webConfigJSON = {
357362
folderUri: folderUri,
358363
staticExtensions,
364+
enableSyncByDefault: args['enable-sync'],
359365
};
360366
if (args['wrap-iframe']) {
361367
webConfigJSON._wrapWebWorkerExtHostInIframe = true;
362368
}
363369

370+
const credentials = [];
371+
if (args['github-auth']) {
372+
const sessionId = uuid.v4();
373+
credentials.push({
374+
service: 'code-oss.login',
375+
account: 'account',
376+
password: JSON.stringify({
377+
id: sessionId,
378+
providerId: 'github',
379+
accessToken: args['github-auth']
380+
})
381+
}, {
382+
service: 'code-oss-github.login',
383+
account: 'account',
384+
password: JSON.stringify([{
385+
id: sessionId,
386+
scopes: ['user:email'],
387+
accessToken: args['github-auth']
388+
}])
389+
});
390+
}
391+
364392
const data = (await readFile(WEB_MAIN)).toString()
365393
.replace('{{WORKBENCH_WEB_CONFIGURATION}}', () => escapeAttribute(JSON.stringify(webConfigJSON))) // use a replace function to avoid that regexp replace patterns ($&, $0, ...) are applied
366394
.replace('{{WORKBENCH_BUILTIN_EXTENSIONS}}', () => escapeAttribute(JSON.stringify(dedupedBuiltInExtensions)))
395+
.replace('{{WORKBENCH_CREDENTIALS}}', () => escapeAttribute(JSON.stringify(credentials)))
367396
.replace('{{WEBVIEW_ENDPOINT}}', '')
368397
.replace('{{REMOTE_USER_DATA_URI}}', '');
369398

src/vs/code/browser/workbench/workbench-dev.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<!-- Builtin Extensions (running out of sources) -->
1818
<meta id="vscode-workbench-builtin-extensions" data-settings="{{WORKBENCH_BUILTIN_EXTENSIONS}}">
1919

20+
<!-- Workbench Credentials (running out of sources) -->
21+
<meta id="vscode-workbench-credentials" data-settings="{{WORKBENCH_CREDENTIALS}}">
22+
2023
<!-- Workarounds/Hacks (remote user data uri) -->
2124
<meta id="vscode-remote-user-data-uri" data-settings="{{REMOTE_USER_DATA_URI}}">
2225

src/vs/code/browser/workbench/workbench.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class LocalStorageCredentialsProvider implements ICredentialsProvider {
2727

2828
static readonly CREDENTIALS_OPENED_KEY = 'credentials.provider';
2929

30+
constructor(credentials: ICredential[]) {
31+
this._credentials = credentials;
32+
for (const { service, account, password } of this._credentials) {
33+
this.setPassword(service, account, password);
34+
}
35+
}
36+
3037
private _credentials: ICredential[] | undefined;
3138
private get credentials(): ICredential[] {
3239
if (!this._credentials) {
@@ -430,6 +437,11 @@ class WindowIndicator implements IWindowIndicator {
430437
window.location.href = `${window.location.origin}?${queryString}`;
431438
};
432439

440+
// Find credentials from DOM
441+
const credentialsElement = document.getElementById('vscode-workbench-credentials');
442+
const credentialsElementAttribute = credentialsElement ? credentialsElement.getAttribute('data-settings') : undefined;
443+
const credentialsProvider = new LocalStorageCredentialsProvider(credentialsElementAttribute ? JSON.parse(credentialsElementAttribute) : []);
444+
433445
// Finally create workbench
434446
create(document.body, {
435447
...config,
@@ -438,6 +450,6 @@ class WindowIndicator implements IWindowIndicator {
438450
productQualityChangeHandler,
439451
workspaceProvider,
440452
urlCallbackProvider: new PollingURLCallbackProvider(),
441-
credentialsProvider: new LocalStorageCredentialsProvider()
453+
credentialsProvider
442454
});
443455
})();

0 commit comments

Comments
 (0)