Skip to content

Commit 8157ad6

Browse files
committed
Fix issues surrounding authentication and login.
- Added product config to client, iframe config.
1 parent d69acb8 commit 8157ad6

File tree

8 files changed

+58
-28
lines changed

8 files changed

+58
-28
lines changed

src/vs/base/common/auth.ts

+10
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

+7-3
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

+1-1
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

+1-1
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

+3
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

+8
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
'connectionToken': { type: 'string' },
1719
'connection-secret': { type: 'string', description: nls.localize('connection-secret', "Path to file that contains the connection token. This will require that all incoming connections know the secret.") },
@@ -58,6 +60,7 @@ export const serverOptions: OptionDescriptions<ServerParsedArgs> = {
5860
};
5961

6062
export interface ServerParsedArgs {
63+
auth?: AuthType;
6164
port?: string;
6265
connectionToken?: string;
6366
/**
@@ -122,11 +125,16 @@ export interface IServerEnvironmentService extends INativeEnvironmentService {
122125
readonly serviceWorkerFileName: string;
123126
readonly serviceWorkerPath: string;
124127
readonly proxyUri: string;
128+
readonly auth: AuthType;
125129
}
126130

127131
export class ServerEnvironmentService extends NativeEnvironmentService implements IServerEnvironmentService {
128132
override get args(): ServerParsedArgs { return super.args as ServerParsedArgs; }
129133

134+
public get auth(): AuthType {
135+
return this.args['auth'] || AuthType.None;
136+
}
137+
130138
public get serviceWorkerFileName(): string {
131139
return 'service-worker.js';
132140
}

src/vs/server/webClientServer.ts

+16-4
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

+12-19
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)