Skip to content

Commit 59023b5

Browse files
committed
support auth in web playground
1 parent cca20eb commit 59023b5

5 files changed

Lines changed: 48 additions & 25 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
<!-- Workbench Configuration -->
1515
<meta id="vscode-workbench-web-configuration" data-settings="{{WORKBENCH_WEB_CONFIGURATION}}">
1616

17+
<!-- Workbench Credentials -->
18+
<meta id="vscode-workbench-credentials" data-settings="{{WORKBENCH_CREDENTIALS}}">
19+
1720
<!-- Builtin Extensions (running out of sources) -->
1821
<meta id="vscode-workbench-builtin-extensions" data-settings="{{WORKBENCH_BUILTIN_EXTENSIONS}}">
1922

20-
<!-- Workbench Credentials (running out of sources) -->
21-
<meta id="vscode-workbench-credentials" data-settings="{{WORKBENCH_CREDENTIALS}}">
22-
2323
<!-- Workbench Icon/Manifest/CSS -->
2424
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
2525
<link rel="manifest" href="/manifest.json">

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<!-- Workbench Configuration -->
1515
<meta id="vscode-workbench-web-configuration" data-settings="{{WORKBENCH_WEB_CONFIGURATION}}">
1616

17+
<!-- Workbench Credentials -->
18+
<meta id="vscode-workbench-credentials" data-settings="{{WORKBENCH_CREDENTIALS}}">
19+
1720
<!-- Workbench Icon/Manifest/CSS -->
1821
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
1922
<link rel="manifest" href="/manifest.json">

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

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ import { isStandalone } from 'vs/base/browser/browser';
1717
import { localize } from 'vs/nls';
1818
import { Schemas } from 'vs/base/common/network';
1919

20+
function doCreateUri(path: string, queryValues: Map<string, string>): URI {
21+
let query: string | undefined = undefined;
22+
23+
if (queryValues) {
24+
let index = 0;
25+
queryValues.forEach((value, key) => {
26+
if (!query) {
27+
query = '';
28+
}
29+
30+
const prefix = (index++ === 0) ? '' : '&';
31+
query += `${prefix}${key}=${encodeURIComponent(value)}`;
32+
});
33+
}
34+
35+
return URI.parse(window.location.href).with({ path, query });
36+
}
37+
2038
interface ICredential {
2139
service: string;
2240
account: string;
@@ -68,14 +86,30 @@ class LocalStorageCredentialsProvider implements ICredentialsProvider {
6886
}
6987

7088
async setPassword(service: string, account: string, password: string): Promise<void> {
71-
this.deletePassword(service, account);
89+
this.doDeletePassword(service, account);
7290

7391
this.credentials.push({ service, account, password });
7492

7593
this.save();
7694
}
7795

7896
async deletePassword(service: string, account: string): Promise<boolean> {
97+
const result = await this.doDeletePassword(service, account);
98+
99+
if (result) {
100+
const queryValues: Map<string, string> = new Map();
101+
queryValues.set('logout', String(true));
102+
queryValues.set('service', service);
103+
104+
await request({
105+
url: doCreateUri('/auth/logout', queryValues).toString(true)
106+
}, CancellationToken.None);
107+
}
108+
109+
return result;
110+
}
111+
112+
async doDeletePassword(service: string, account: string): Promise<boolean> {
79113
let found = false;
80114

81115
this._credentials = this.credentials.filter(credential => {
@@ -154,7 +188,7 @@ class PollingURLCallbackProvider extends Disposable implements IURLCallbackProvi
154188
// Start to poll on the callback being fired
155189
this.periodicFetchCallback(requestId, Date.now());
156190

157-
return this.doCreateUri('/callback', queryValues);
191+
return doCreateUri('/callback', queryValues);
158192
}
159193

160194
private async periodicFetchCallback(requestId: string, startTime: number): Promise<void> {
@@ -164,7 +198,7 @@ class PollingURLCallbackProvider extends Disposable implements IURLCallbackProvi
164198
queryValues.set(PollingURLCallbackProvider.QUERY_KEYS.REQUEST_ID, requestId);
165199

166200
const result = await request({
167-
url: this.doCreateUri('/fetch-callback', queryValues).toString(true)
201+
url: doCreateUri('/fetch-callback', queryValues).toString(true)
168202
}, CancellationToken.None);
169203

170204
// Check for callback results
@@ -185,23 +219,6 @@ class PollingURLCallbackProvider extends Disposable implements IURLCallbackProvi
185219
}
186220
}
187221

188-
private doCreateUri(path: string, queryValues: Map<string, string>): URI {
189-
let query: string | undefined = undefined;
190-
191-
if (queryValues) {
192-
let index = 0;
193-
queryValues.forEach((value, key) => {
194-
if (!query) {
195-
query = '';
196-
}
197-
198-
const prefix = (index++ === 0) ? '' : '&';
199-
query += `${prefix}${key}=${encodeURIComponent(value)}`;
200-
});
201-
}
202-
203-
return URI.parse(window.location.href).with({ path, query });
204-
}
205222
}
206223

207224
class WorkspaceProvider implements IWorkspaceProvider {

src/vs/workbench/browser/parts/activitybar/activitybarActions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ export class AccountsActionViewItem extends ActivityActionViewItem {
200200
return this.authenticationService.signOutOfAccount(sessionInfo.providerId, accountName);
201201
});
202202

203-
const actions = hasEmbedderAccountSession ? [manageExtensionsAction] : [manageExtensionsAction, signOutAction];
203+
const actions = [manageExtensionsAction];
204+
if (!hasEmbedderAccountSession || authenticationSession?.canSignOut) {
205+
actions.push(signOutAction);
206+
}
204207

205208
const menu = new SubmenuAction('activitybar.submenu', `${accountName} (${providerDisplayName})`, actions);
206209
menus.push(menu);

src/vs/workbench/services/authentication/browser/authenticationService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
2626

2727
export function getAuthenticationProviderActivationEvent(id: string): string { return `onAuthenticationRequest:${id}`; }
2828

29-
export type AuthenticationSessionInfo = { readonly id: string, readonly accessToken: string, readonly providerId: string };
29+
export type AuthenticationSessionInfo = { readonly id: string, readonly accessToken: string, readonly providerId: string, readonly canSignOut?: boolean };
3030
export async function getCurrentAuthenticationSessionInfo(environmentService: IWorkbenchEnvironmentService, productService: IProductService): Promise<AuthenticationSessionInfo | undefined> {
3131
if (environmentService.options?.credentialsProvider) {
3232
const authenticationSessionValue = await environmentService.options.credentialsProvider.getPassword(`${productService.urlProtocol}.login`, 'account');

0 commit comments

Comments
 (0)