diff --git a/generator/src/templates/theiaPlugins.json b/generator/src/templates/theiaPlugins.json index af5f4b0a2..67217ee88 100644 --- a/generator/src/templates/theiaPlugins.json +++ b/generator/src/templates/theiaPlugins.json @@ -55,6 +55,7 @@ "vscode-builtin-yaml": "https://open-vsx.org/api/vscode/yaml/1.44.2/file/vscode.yaml-1.44.2.vsix", "vscode-eslint": "https://open-vsx.org/api/dbaeumer/vscode-eslint/2.1.1/file/dbaeumer.vscode-eslint-2.1.1.vsix", "vscode-git": "https://open-vsx.org/api/vscode/git/1.49.3/file/vscode.git-1.49.3.vsix", + "vscode-github": "https://open-vsx.org/api/vscode/github/1.50.1/file/vscode.github-1.50.1.vsix", "vscode-references-view": "https://open-vsx.org/api/ms-vscode/references-view/0.0.47/file/ms-vscode.references-view-0.0.47.vsix", "vscode-builtin-icon-theme-seti": "https://open-vsx.org/api/vscode/vscode-theme-seti/1.44.2/file/vscode.vscode-theme-seti-1.44.2.vsix", "vscode-builtin-theme-abyss": "https://open-vsx.org/api/vscode/theme-abyss/1.44.2/file/vscode.theme-abyss-1.44.2.vsix", diff --git a/plugins/github-auth-plugin/package.json b/plugins/github-auth-plugin/package.json index 1c7299b94..9f0e08d0f 100644 --- a/plugins/github-auth-plugin/package.json +++ b/plugins/github-auth-plugin/package.json @@ -14,6 +14,9 @@ "activationEvents": [ "*" ], + "dependencies": { + "uuid": "^3.1.0" + }, "devDependencies": { "@theia/plugin": "next", "@theia/plugin-packager": "latest", diff --git a/plugins/github-auth-plugin/src/github-auth-plugin.ts b/plugins/github-auth-plugin/src/github-auth-plugin.ts index b62f30916..3f5d3f34e 100644 --- a/plugins/github-auth-plugin/src/github-auth-plugin.ts +++ b/plugins/github-auth-plugin/src/github-auth-plugin.ts @@ -10,45 +10,49 @@ import * as theia from '@theia/plugin'; import * as che from '@eclipse-che/plugin'; +import { v4 } from 'uuid'; export async function start(context: theia.PluginContext): Promise { - if (theia.plugins.getPlugin('github.vscode-pull-request-github')) { - let session: theia.AuthenticationSession | undefined = context.workspaceState.get('session'); - const onDidChangeSessions = new theia.EventEmitter(); - theia.authentication.registerAuthenticationProvider({ + const sessions: theia.AuthenticationSession[] = context.workspaceState.get('sessions') || []; + const onDidChangeSessions = new theia.EventEmitter(); + theia.authentication.registerAuthenticationProvider({ id: 'github', label: 'GitHub', supportsMultipleAccounts: false, onDidChangeSessions: onDidChangeSessions.event, - getSessions: async () => { - if (session) { - return [session]; - } else { - return []; - } - }, + getSessions: async () => sessions, login: async (scopes: string[]) => { const githubUser = await che.github.getUser(); - session = { - id: 'github-session', + const session = { + id: v4(), accessToken: await che.github.getToken(), account: { label: githubUser.login, id: githubUser.id.toString() }, scopes }; - context.workspaceState.update('session', session); + const sessionIndex = sessions.findIndex(s => s.id === session.id); + if (sessionIndex > -1) { + sessions.splice(sessionIndex, 1, session); + } else { + sessions.push(session); + } + context.workspaceState.update('sessions', sessions); onDidChangeSessions.fire({ added: [session.id], removed: [], changed: [] }); return session; }, logout: async (id: string) => { - session = undefined; - context.workspaceState.update('session', session); - onDidChangeSessions.fire({ added: [], removed: [id], changed: [] }); + const sessionIndex = sessions.findIndex(session => session.id === id); + if (sessionIndex > -1) { + sessions.splice(sessionIndex, 1); + context.workspaceState.update('sessions', sessions); + onDidChangeSessions.fire({ added: [], removed: [id], changed: [] }); + } } } - ); - if (session) { - onDidChangeSessions.fire({ added: [session.id], removed: [], changed: [] }); - // TODO Remove the notification when https://github.com/eclipse-theia/theia/issues/7178 is fixed. + ); + if (theia.plugins.getPlugin('github.vscode-pull-request-github')) { + if (sessions.length > 0) { + onDidChangeSessions.fire({ added: sessions.map(s => s.id), removed: [], changed: [] }); + // TODO Remove the notification when https://github.com/eclipse-theia/theia/issues/7178 is fixed. } else { const signIn = 'Sign in'; const result = await theia.window.showInformationMessage(