From 55f8babe6f2db68e120370af7005d1b8280d6007 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 25 Sep 2023 15:51:53 -0800 Subject: [PATCH] Remove unnecessary GitHub auth patch It works now without the patch. --- patches/github-auth.diff | 106 --------------------------------------- patches/series | 1 - 2 files changed, 107 deletions(-) delete mode 100644 patches/github-auth.diff diff --git a/patches/github-auth.diff b/patches/github-auth.diff deleted file mode 100644 index 20ab57e42724..000000000000 --- a/patches/github-auth.diff +++ /dev/null @@ -1,106 +0,0 @@ -Add the ability to provide a GitHub token - -To test install the GitHub PR extension and start code-server with GITHUB_TOKEN -or set github-auth in the config file. The extension should be authenticated. - -Index: code-server/lib/vscode/src/vs/platform/credentials/node/credentialsMainService.ts -=================================================================== ---- code-server.orig/lib/vscode/src/vs/platform/credentials/node/credentialsMainService.ts -+++ code-server/lib/vscode/src/vs/platform/credentials/node/credentialsMainService.ts -@@ -5,9 +5,18 @@ - - import { InMemoryCredentialsProvider } from 'vs/platform/credentials/common/credentials'; - import { ILogService } from 'vs/platform/log/common/log'; --import { INativeEnvironmentService } from 'vs/platform/environment/common/environment'; -+import { IServerEnvironmentService } from 'vs/server/node/serverEnvironmentService'; - import { IProductService } from 'vs/platform/product/common/productService'; - import { BaseCredentialsMainService, KeytarModule } from 'vs/platform/credentials/common/credentialsMainService'; -+import { generateUuid } from 'vs/base/common/uuid'; -+import { equals as arrayEquals } from 'vs/base/common/arrays'; -+ -+interface IToken { -+ accessToken: string -+ account?: { label: string } -+ id: string -+ scopes: string[] -+} - - export class CredentialsWebMainService extends BaseCredentialsMainService { - // Since we fallback to the in-memory credentials provider, we do not need to surface any Keytar load errors -@@ -16,10 +25,15 @@ export class CredentialsWebMainService e - - constructor( - @ILogService logService: ILogService, -- @INativeEnvironmentService private readonly environmentMainService: INativeEnvironmentService, -+ @IServerEnvironmentService private readonly environmentMainService: IServerEnvironmentService, - @IProductService private readonly productService: IProductService, - ) { - super(logService); -+ if (this.environmentMainService.args["github-auth"]) { -+ this.storeGitHubToken(this.environmentMainService.args["github-auth"]).catch((error) => { -+ this.logService.error('Failed to store provided GitHub token', error) -+ }) -+ } - } - - // If the credentials service is running on the server, we add a suffix -server to differentiate from the location that the -@@ -48,4 +62,59 @@ export class CredentialsWebMainService e - } - return this._keytarCache; - } -+ -+ private async storeGitHubToken(githubToken: string): Promise { -+ const extensionId = 'vscode.github-authentication'; -+ const service = `${await this.getSecretStoragePrefix()}${extensionId}`; -+ const account = 'github.auth'; -+ const scopes = [['read:user', 'user:email', 'repo']] -+ -+ // Oddly the scopes need to match exactly so we cannot just have one token -+ // with all the scopes, instead we have to duplicate the token for each -+ // expected set of scopes. -+ const tokens: IToken[] = scopes.map((scopes) => ({ -+ id: generateUuid(), -+ scopes: scopes.sort(), // Sort for comparing later. -+ accessToken: githubToken, -+ })); -+ -+ const raw = await this.getPassword(service, account) -+ -+ let existing: { -+ content: IToken[] -+ } | undefined; -+ -+ if (raw) { -+ try { -+ const json = JSON.parse(raw); -+ json.content = JSON.parse(json.content); -+ existing = json; -+ } catch (error) { -+ this.logService.error('Failed to parse existing GitHub credentials', error) -+ } -+ } -+ -+ // Keep tokens for account and scope combinations we do not have in case -+ // there is an extension that uses scopes we have not accounted for (in -+ // these cases the user will need to manually authenticate the extension -+ // through the UI) or the user has tokens for other accounts. -+ if (existing?.content) { -+ existing.content = existing.content.filter((existingToken) => { -+ const scopes = existingToken.scopes.sort(); -+ return !(tokens.find((token) => { -+ return arrayEquals(scopes, token.scopes) -+ && token.account?.label === existingToken.account?.label; -+ })) -+ }) -+ } -+ -+ return this.setPassword(service, account, JSON.stringify({ -+ extensionId, -+ ...(existing || {}), -+ content: JSON.stringify([ -+ ...tokens, -+ ...(existing?.content || []), -+ ]) -+ })); -+ } - } diff --git a/patches/series b/patches/series index dba2e20a31a5..898d2974af05 100644 --- a/patches/series +++ b/patches/series @@ -9,7 +9,6 @@ update-check.diff logout.diff store-socket.diff proxy-uri.diff -github-auth.diff unique-db.diff local-storage.diff service-worker.diff