Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/patches/logout.diff
Asher a1af9e2a56
chore: move to patches (#4997)
* Move integration types into code-server

This will be easier to maintain than to have it as a patch.

* Disable connection token

Using a flag means we will not need to patch it out.  I think this is
new from 1.64?

* Add product.json to build process

This way we do not have to patch it.

* Ship with remote agent package.json

Instead of the root one.  This contains fewer dependencies.

* Let Code handle errors

This way we will not have to patch Code to make this work and I think it
makes sense to let Code handle the request.

If we do want to handle errors we can do it cleanly by patching their
error handler to throw instead.

* Move manifest override into code-server

This way we will not have to patch it.

* Move to patches

- Switch submodule to track upstream
- Add quilt to the process
- Add patches

The node-* ignore was ignoring one of the diffs so I removed it.  This
was added when we were curling Node as node-v{version}-darwin-x64 for
the macOS build but this no longer happens (we use the Node action to
install a specific version now so we just use the system-wide Node).

* Use pre-packaged Code
2022-03-22 15:07:14 -05:00

108 lines
4.6 KiB
Diff

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
@@ -34,6 +34,7 @@ export interface IProductConfiguration {
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
@@ -13,6 +13,7 @@ import { IEnvironmentService, INativeEnv
export const serverOptions: OptionDescriptions<ServerParsedArgs> = {
/* ----- code-server ----- */
'disable-update-check': { type: 'boolean' },
+ 'auth': { type: 'string' },
/* ----- server setup ----- */
@@ -88,6 +89,7 @@ export const serverOptions: OptionDescri
export interface ServerParsedArgs {
/* ----- code-server ----- */
'disable-update-check'?: boolean;
+ 'auth'?: string
/* ----- 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
@@ -287,6 +287,7 @@ export class WebClientServer {
productConfiguration: <Partial<IProductConfiguration>>{
rootEndpoint: base,
updateEndpoint: !this._environmentService.args['disable-update-check'] ? base + '/update/check' : undefined,
+ logoutEndpoint: this._environmentService.args['auth'] ? base + '/logout' : undefined,
extensionsGallery: {
...this._productService.extensionsGallery,
'resourceUrlTemplate': this._webExtensionResourceUrlTemplate ? this._webExtensionResourceUrlTemplate.with({
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,
@@ -82,6 +86,10 @@ export class CodeServerClient extends Di
if (this.productService.updateEndpoint) {
this.checkUpdates(this.productService.updateEndpoint)
}
+
+ if (this.productService.logoutEndpoint) {
+ this.addLogoutCommand(this.productService.logoutEndpoint);
+ }
}
private checkUpdates(updateEndpoint: string) {
@@ -133,4 +141,25 @@ export class CodeServerClient extends Di
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'),
+ },
+ });
+ }
+ }
}