Skip to content

Commit e7756c8

Browse files
reinstate github-auth parameter that was accidentally removed (microsoft#191862)
Fixes microsoft#191861
1 parent 7bfd9cb commit e7756c8

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import product from 'vs/platform/product/common/product';
1717
import { ISecretStorageProvider } from 'vs/platform/secrets/common/secrets';
1818
import { isFolderToOpen, isWorkspaceToOpen } from 'vs/platform/window/common/window';
1919
import type { IWorkbenchConstructionOptions } from 'vs/workbench/browser/web.api';
20+
import { AuthenticationSessionInfo } from 'vs/workbench/services/authentication/browser/authenticationService';
2021
import type { IWorkspace, IWorkspaceProvider } from 'vs/workbench/services/host/browser/browserHostService';
2122
import type { IURLCallbackProvider } from 'vs/workbench/services/url/browser/urlService';
2223
import { create } from 'vs/workbench/workbench.web.main';
@@ -176,19 +177,56 @@ export class LocalStorageSecretStorageProvider implements ISecretStorageProvider
176177
) { }
177178

178179
private async load(): Promise<Record<string, string>> {
180+
const record = this.loadAuthSessionFromElement();
179181
// Get the secrets from localStorage
180182
const encrypted = window.localStorage.getItem(this._storageKey);
181183
if (encrypted) {
182184
try {
183-
return JSON.parse(await this.crypto.unseal(encrypted));
185+
const decrypted = JSON.parse(await this.crypto.unseal(encrypted));
186+
return { ...record, ...decrypted };
184187
} catch (err) {
185188
// TODO: send telemetry
186189
console.error('Failed to decrypt secrets from localStorage', err);
187190
window.localStorage.removeItem(this._storageKey);
188191
}
189192
}
190193

191-
return {};
194+
return record;
195+
}
196+
197+
private loadAuthSessionFromElement(): Record<string, string> {
198+
let authSessionInfo: (AuthenticationSessionInfo & { scopes: string[][] }) | undefined;
199+
const authSessionElement = document.getElementById('vscode-workbench-auth-session');
200+
const authSessionElementAttribute = authSessionElement ? authSessionElement.getAttribute('data-settings') : undefined;
201+
if (authSessionElementAttribute) {
202+
try {
203+
authSessionInfo = JSON.parse(authSessionElementAttribute);
204+
} catch (error) { /* Invalid session is passed. Ignore. */ }
205+
}
206+
207+
if (!authSessionInfo) {
208+
return {};
209+
}
210+
211+
const record: Record<string, string> = {};
212+
213+
// Settings Sync Entry
214+
record[`${product.urlProtocol}.loginAccount`] = JSON.stringify(authSessionInfo);
215+
216+
// Auth extension Entry
217+
if (authSessionInfo.providerId !== 'github') {
218+
console.error(`Unexpected auth provider: ${authSessionInfo.providerId}. Expected 'github'.`);
219+
return record;
220+
}
221+
222+
const authAccount = JSON.stringify({ extensionId: 'vscode.github-authentication', key: 'github.auth' });
223+
record[authAccount] = JSON.stringify(authSessionInfo.scopes.map(scopes => ({
224+
id: authSessionInfo!.id,
225+
scopes,
226+
accessToken: authSessionInfo!.accessToken
227+
})));
228+
229+
return record;
192230
}
193231

194232
async get(key: string): Promise<string | undefined> {

0 commit comments

Comments
 (0)