2022-03-23 04:07:14 +08:00
|
|
|
Add a logout command and menu item
|
|
|
|
|
|
|
|
This will only show if you have authentication enabled.
|
|
|
|
|
|
|
|
This has e2e tests but are currently disabled and need to be fixed.
|
|
|
|
|
|
|
|
Index: code-server/lib/vscode/src/vs/base/common/product.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/base/common/product.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/base/common/product.ts
|
2023-04-11 02:28:13 +08:00
|
|
|
@@ -58,6 +58,7 @@ export interface IProductConfiguration {
|
2022-03-23 04:07:14 +08:00
|
|
|
readonly codeServerVersion?: string
|
|
|
|
readonly rootEndpoint?: string
|
|
|
|
readonly updateEndpoint?: string
|
|
|
|
+ readonly logoutEndpoint?: string
|
|
|
|
|
|
|
|
readonly version: string;
|
|
|
|
readonly date?: string;
|
|
|
|
Index: code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
|
2023-09-21 07:33:28 +08:00
|
|
|
@@ -15,6 +15,7 @@ import { URI } from 'vs/base/common/uri'
|
2022-11-10 06:10:03 +08:00
|
|
|
export const serverOptions: OptionDescriptions<Required<ServerParsedArgs>> = {
|
2022-03-23 04:07:14 +08:00
|
|
|
/* ----- code-server ----- */
|
|
|
|
'disable-update-check': { type: 'boolean' },
|
|
|
|
+ 'auth': { type: 'string' },
|
|
|
|
|
|
|
|
/* ----- server setup ----- */
|
|
|
|
|
2024-04-06 06:20:28 +08:00
|
|
|
@@ -97,6 +98,7 @@ export const serverOptions: OptionDescri
|
2022-03-23 04:07:14 +08:00
|
|
|
export interface ServerParsedArgs {
|
|
|
|
/* ----- code-server ----- */
|
|
|
|
'disable-update-check'?: boolean;
|
2024-05-07 08:31:33 +08:00
|
|
|
+ 'auth'?: string;
|
2022-03-23 04:07:14 +08:00
|
|
|
|
|
|
|
/* ----- server setup ----- */
|
|
|
|
|
|
|
|
Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/server/node/webClientServer.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/server/node/webClientServer.ts
|
2024-08-03 05:43:43 +08:00
|
|
|
@@ -311,6 +311,7 @@ export class WebClientServer {
|
2023-05-16 07:44:03 +08:00
|
|
|
codeServerVersion: this._productService.codeServerVersion,
|
|
|
|
rootEndpoint: base,
|
|
|
|
updateEndpoint: !this._environmentService.args['disable-update-check'] ? base + '/update/check' : undefined,
|
|
|
|
+ logoutEndpoint: this._environmentService.args['auth'] && this._environmentService.args['auth'] !== "none" ? base + '/logout' : undefined,
|
|
|
|
embedderIdentifier: 'server-distro',
|
|
|
|
extensionsGallery: this._productService.extensionsGallery,
|
2024-06-07 07:02:13 +08:00
|
|
|
} satisfies Partial<IProductConfiguration>;
|
2022-03-23 04:07:14 +08:00
|
|
|
Index: code-server/lib/vscode/src/vs/workbench/browser/client.ts
|
|
|
|
===================================================================
|
|
|
|
--- code-server.orig/lib/vscode/src/vs/workbench/browser/client.ts
|
|
|
|
+++ code-server/lib/vscode/src/vs/workbench/browser/client.ts
|
|
|
|
@@ -1,11 +1,15 @@
|
|
|
|
import { Disposable } from 'vs/base/common/lifecycle';
|
|
|
|
import { localize } from 'vs/nls';
|
|
|
|
+import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
|
|
|
|
+import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
|
|
|
import { ILogService } from 'vs/platform/log/common/log';
|
|
|
|
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
|
|
|
|
import { IProductService } from 'vs/platform/product/common/productService';
|
|
|
|
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
|
|
|
|
|
|
|
|
export class CodeServerClient extends Disposable {
|
|
|
|
+ static LOGOUT_COMMAND_ID = 'code-server.logout';
|
|
|
|
+
|
|
|
|
constructor (
|
|
|
|
@ILogService private logService: ILogService,
|
|
|
|
@INotificationService private notificationService: INotificationService,
|
2022-09-16 05:49:28 +08:00
|
|
|
@@ -81,6 +85,10 @@ export class CodeServerClient extends Di
|
2022-03-23 04:07:14 +08:00
|
|
|
if (this.productService.updateEndpoint) {
|
|
|
|
this.checkUpdates(this.productService.updateEndpoint)
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ if (this.productService.logoutEndpoint) {
|
|
|
|
+ this.addLogoutCommand(this.productService.logoutEndpoint);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
private checkUpdates(updateEndpoint: string) {
|
2022-09-16 05:49:28 +08:00
|
|
|
@@ -132,4 +140,25 @@ export class CodeServerClient extends Di
|
2022-03-23 04:07:14 +08:00
|
|
|
|
|
|
|
updateLoop();
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ private addLogoutCommand(logoutEndpoint: string) {
|
|
|
|
+ CommandsRegistry.registerCommand(CodeServerClient.LOGOUT_COMMAND_ID, () => {
|
|
|
|
+ const logoutUrl = new URL(logoutEndpoint, window.location.href);
|
|
|
|
+ // Cookies must be set with absolute paths and must use the same path to
|
|
|
|
+ // be unset (we set it on the root) so send the relative root and the
|
|
|
|
+ // current href so the backend can derive the absolute path to the root.
|
|
|
|
+ logoutUrl.searchParams.set('base', this.productService.rootEndpoint || ".");
|
|
|
|
+ logoutUrl.searchParams.set('href', window.location.href);
|
|
|
|
+ window.location.assign(logoutUrl);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ for (const menuId of [MenuId.CommandPalette, MenuId.MenubarHomeMenu]) {
|
|
|
|
+ MenuRegistry.appendMenuItem(menuId, {
|
|
|
|
+ command: {
|
|
|
|
+ id: CodeServerClient.LOGOUT_COMMAND_ID,
|
|
|
|
+ title: localize('logout', "Sign out of {0}", 'code-server'),
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
}
|