Skip to content

Commit d617bc6

Browse files
GirlBossRushZauberNerd
authored andcommitted
Fix issues surrounding authentication and login.
- Added product config to client, iframe config.
1 parent 00eb75d commit d617bc6

File tree

8 files changed

+58
-28
lines changed

8 files changed

+58
-28
lines changed

src/vs/base/common/auth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable header/header */
2+
/*---------------------------------------------------------------------------------------------
3+
* Copyright (c) Coder Technologies. All rights reserved.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
export enum AuthType {
8+
Password = 'password',
9+
None = 'none',
10+
}

src/vs/base/common/product.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { IStringDictionary } from 'vs/base/common/collections';
7+
import { AuthType } from 'vs/base/common/auth';
78

89
export interface IBuiltInExtension {
910
readonly name: string;
@@ -31,17 +32,20 @@ export type ExtensionVirtualWorkspaceSupport = {
3132
};
3233

3334
export interface IProductConfiguration {
34-
// @coder BEGIN
35+
//#region Code Server Additions
36+
3537
readonly codeServerVersion?: string;
36-
readonly authed?: boolean;
38+
readonly auth?: AuthType;
39+
3740
readonly logoutEndpointUrl: string;
3841
readonly proxyEndpointUrlTemplate?: string;
3942
readonly serviceWorker?: {
4043
readonly url: string;
4144
readonly scope: string;
4245
}
4346
readonly icons: Array<{ src: string; type: string; sizes: string }>;
44-
// @coder END */
47+
48+
//#regionend
4549

4650
readonly version: string;
4751
readonly date?: string;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<meta name="theme-color" content="{{CLIENT_BACKGROUND_COLOR}}">
3333

3434
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
35-
<link rel="manifest" href="./manifest.json">
35+
<link rel="manifest" href="./manifest.json" crossorigin="use-credentials">
3636
</head>
3737

3838
<body style="background-color: var(--vs-theme-background-color); color: var(--vs-theme-foreground-color)" aria-label="">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<!-- Workbench Icon/Manifest/CSS -->
1111
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
12-
<link rel="manifest" href="./manifest.json">
12+
<link rel="manifest" href="./manifest.json" crossorigin="use-credentials">
1313

1414
<meta name="theme-color" content="{{CLIENT_BACKGROUND_COLOR}}">
1515

src/vs/server/@types/code-server-lib/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
import type { NLSConfiguration, InternalNLSConfiguration } from '../../../base/node/languagePacks';
88
import type * as http from 'http';
99
import type * as net from 'net';
10+
import type { AuthType } from 'vs/base/common/auth';
1011

1112
declare global {
1213
namespace CodeServerLib {
14+
1315
export interface ServerParsedArgs {
16+
auth: AuthType;
1417
port?: string;
1518
connectionToken?: string;
1619
/**

src/vs/server/serverEnvironmentService.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import { refineServiceDecorator } from 'vs/platform/instantiation/common/instant
1010
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
1111
import { memoize } from 'vs/base/common/decorators';
1212
import { FileAccess } from 'vs/base/common/network';
13+
import { AuthType } from 'vs/base/common/auth';
1314

1415
export const serverOptions: OptionDescriptions<ServerParsedArgs> = {
16+
'auth': { type: 'string' },
1517
'port': { type: 'string' },
1618
'pick-port': { type: 'string' },
1719
'connection-token': { type: 'string', cat: 'o', deprecates: 'connectionToken', description: nls.localize('connection-token', "A secret that must be included by the web client with all requests.") },
@@ -63,6 +65,7 @@ export const serverOptions: OptionDescriptions<ServerParsedArgs> = {
6365
};
6466

6567
export interface ServerParsedArgs {
68+
auth?: AuthType;
6669
port?: string;
6770
'pick-port'?: string;
6871
/**
@@ -145,11 +148,16 @@ export interface IServerEnvironmentService extends INativeEnvironmentService {
145148
readonly serviceWorkerFileName: string;
146149
readonly serviceWorkerPath: string;
147150
readonly proxyUri: string;
151+
readonly auth: AuthType;
148152
}
149153

150154
export class ServerEnvironmentService extends NativeEnvironmentService implements IServerEnvironmentService {
151155
override get args(): ServerParsedArgs { return super.args as ServerParsedArgs; }
152156

157+
public get auth(): AuthType {
158+
return this.args['auth'] || AuthType.None;
159+
}
160+
153161
public get serviceWorkerFileName(): string {
154162
return 'service-worker.js';
155163
}

src/vs/server/webClientServer.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ export class WebClientServer {
186186
return undefined;
187187
};
188188

189-
const proto = parseHeaders(["X-Forwarded-Proto"]) || "http";
190-
const host = parseHeaders(["X-Forwarded-Host", "host"]) || "localhost";
189+
const proto = parseHeaders(['X-Forwarded-Proto']) || 'http';
190+
const host = parseHeaders(['X-Forwarded-Host', 'host']) || 'localhost';
191191

192192
return new URL(`${proto}://${host}`);
193193
}
@@ -303,11 +303,23 @@ export class WebClientServer {
303303
const data = (await util.promisify(fs.readFile)(filePath)).toString()
304304
.replace('{{WORKBENCH_WEB_CONFIGURATION}}', escapeAttribute(JSON.stringify(<IWorkbenchConstructionOptions>{
305305
productConfiguration: {
306-
updateUrl: this.createRequestUrl(req, parsedUrl, '/update/check').toString(),
306+
...this._productService,
307+
308+
// Session
309+
auth: this._environmentService.auth,
310+
311+
// Service Worker
307312
serviceWorker: {
308313
scope: './',
309314
url: `./${this._environmentService.serviceWorkerFileName}`
310-
}
315+
},
316+
317+
// Endpoints
318+
logoutEndpointUrl: this.createRequestUrl(req, parsedUrl, '/logout').toString(),
319+
webEndpointUrl: this.createRequestUrl(req, parsedUrl, '/static').toString(),
320+
webEndpointUrlTemplate: this.createRequestUrl(req, parsedUrl, '/static').toString(),
321+
322+
updateUrl: this.createRequestUrl(req, parsedUrl, '/update/check').toString(),
311323
},
312324
folderUri: (workspacePath && isFolder) ? transformer.transformOutgoing(URI.file(workspacePath)) : undefined,
313325
workspaceUri: (workspacePath && !isFolder) ? transformer.transformOutgoing(URI.file(workspacePath)) : undefined,

src/vs/workbench/browser/client.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
*--------------------------------------------------------------------------------------------*/
66

7+
import { AuthType } from 'vs/base/common/auth';
78
import { Disposable } from 'vs/base/common/lifecycle';
89
import { localize } from 'vs/nls';
910
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
@@ -174,34 +175,26 @@ export class CodeServerClientAdditions extends Disposable {
174175
}
175176

176177
private appendSessionCommands() {
177-
const { authed, logoutEndpointUrl } = this.productConfiguration;
178+
const { auth, logoutEndpointUrl } = this.productConfiguration;
178179

179180
// Use to show or hide logout commands and menu options.
180-
this.contextKeyService.createKey(CodeServerClientAdditions.AUTH_KEY, !!authed);
181+
this.contextKeyService.createKey(CodeServerClientAdditions.AUTH_KEY, auth === AuthType.Password);
181182

182183
CommandsRegistry.registerCommand(CodeServerClientAdditions.LOGOUT_COMMAND_ID, () => {
183184
if (logoutEndpointUrl) {
184185
window.location.href = logoutEndpointUrl;
185186
}
186187
});
187188

188-
// Add logout to command palette.
189-
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
190-
command: {
191-
id: CodeServerClientAdditions.LOGOUT_COMMAND_ID,
192-
title: localize('logout', 'Log out'),
193-
},
194-
when: ContextKeyExpr.has(CodeServerClientAdditions.AUTH_KEY),
195-
});
196-
197-
// Add logout to the (web-only) home menu.
198-
MenuRegistry.appendMenuItem(MenuId.MenubarHomeMenu, {
199-
command: {
200-
id: CodeServerClientAdditions.LOGOUT_COMMAND_ID,
201-
title: localize('logout', 'Log out'),
202-
},
203-
when: ContextKeyExpr.has(CodeServerClientAdditions.AUTH_KEY),
204-
});
189+
for (const menuId of [MenuId.CommandPalette, MenuId.MenubarHomeMenu]) {
190+
MenuRegistry.appendMenuItem(menuId, {
191+
command: {
192+
id: CodeServerClientAdditions.LOGOUT_COMMAND_ID,
193+
title: localize('logout', 'Sign out of {0}', this.productConfiguration.nameShort),
194+
},
195+
when: ContextKeyExpr.has(CodeServerClientAdditions.AUTH_KEY),
196+
});
197+
}
205198
}
206199

207200
private registerServiceWorker = async (): Promise<void> => {

0 commit comments

Comments
 (0)