Skip to content

Commit

Permalink
Apply Authentication plugin API
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
  • Loading branch information
vinokurig committed Sep 9, 2020
1 parent 85a002e commit ecd7321
Show file tree
Hide file tree
Showing 14 changed files with 1,304 additions and 2 deletions.
402 changes: 402 additions & 0 deletions packages/core/src/browser/authentication-service.ts

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import debounce = require('lodash.debounce');
import { injectable, inject } from 'inversify';
import { TabBar, Widget } from '@phosphor/widgets';
import { MAIN_MENU_BAR, SETTINGS_MENU, MenuContribution, MenuModelRegistry } from '../common/menu';
import { MAIN_MENU_BAR, SETTINGS_MENU, MenuContribution, MenuModelRegistry, ACCOUNTS_MENU } from '../common/menu';
import { KeybindingContribution, KeybindingRegistry } from './keybinding';
import { FrontendApplication, FrontendApplicationContribution } from './frontend-application';
import { CommandContribution, CommandRegistry, Command } from '../common/command';
Expand Down Expand Up @@ -51,6 +51,7 @@ import { ClipboardService } from './clipboard-service';
import { EncodingRegistry } from './encoding-registry';
import { UTF8 } from '../common/encodings';
import { EnvVariablesServer } from '../common/env-variables';
import { AuthenticationService } from './authentication-service';

export namespace CommonMenus {

Expand Down Expand Up @@ -327,6 +328,9 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
@inject(EnvVariablesServer)
protected readonly environments: EnvVariablesServer;

@inject(AuthenticationService)
protected readonly authenticationService: AuthenticationService;

async configure(app: FrontendApplication): Promise<void> {
const configDirUri = await this.environments.getConfigDirUri();
// Global settings
Expand Down Expand Up @@ -362,6 +366,21 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
menuPath: SETTINGS_MENU,
order: 0,
});
const accountsMenu = {
id: 'accounts-menu',
iconClass: 'codicon codicon-person',
title: 'Accounts',
menuPath: ACCOUNTS_MENU,
order: 1,
};
this.authenticationService.onDidRegisterAuthenticationProvider(() => {
app.shell.leftPanelHandler.addMenu(accountsMenu);
});
this.authenticationService.onDidUnregisterAuthenticationProvider(() => {
if (this.authenticationService.getProviderIds().length === 0) {
app.shell.leftPanelHandler.removeMenu(accountsMenu.id);
}
});
}

protected updateStyles(): void {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import { CommandOpenHandler } from './command-open-handler';
import { LanguageService } from './language-service';
import { EncodingRegistry } from './encoding-registry';
import { EncodingService } from '../common/encoding-service';
import { AuthenticationService, AuthenticationServiceImpl } from '../browser/authentication-service';

export { bindResourceProvider, bindMessageService, bindPreferenceService };

Expand Down Expand Up @@ -339,4 +340,6 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
});

bind(ContextMenuContext).toSelf().inSingletonScope();

bind(AuthenticationService).to(AuthenticationServiceImpl).inSingletonScope();
});
9 changes: 9 additions & 0 deletions packages/core/src/browser/shell/side-panel-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,15 @@ export class SidePanelHandler {
this.bottomMenu.addMenu(menu);
}

/**
* Remove a menu from the sidebar bottom.
*
* @param menuId id of the menu to remove
*/
removeMenu(menuId: string): void {
this.bottomMenu.removeMenu(menuId);
}

// should be a property to preserve fn identity
protected updateToolbarTitle = (): void => {
const currentTitle = this.tabBar && this.tabBar.currentTitle;
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/browser/shell/sidebar-bottom-menu-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ export class SidebarBottomMenuWidget extends ReactWidget {
this.update();
}

removeMenu(menuId: string): void {
const menu = this.menus.find(m => m.id === menuId);
if (menu) {
const index = this.menus.indexOf(menu);
if (index !== -1) {
this.menus.splice(index, 1);
this.update();
}
}
}

protected onClick(e: React.MouseEvent<HTMLElement, MouseEvent>, menuPath: MenuPath): void {
this.contextMenuRenderer.render({
menuPath,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/common/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export type MenuPath = string[];
export const MAIN_MENU_BAR: MenuPath = ['menubar'];

export const SETTINGS_MENU: MenuPath = ['settings_menu'];
export const ACCOUNTS_MENU: MenuPath = ['accounts_menu'];
export const ACCOUNTS_SUBMENU = [...ACCOUNTS_MENU, '1_accounts_submenu'];

export const MenuContribution = Symbol('MenuContribution');

Expand Down
18 changes: 18 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,21 @@ export interface LinePreview {
text: string;
character: number;
}

export interface AuthenticationSession {
id: string;
accessToken: string;
account: { id: string, label: string };
scopes: ReadonlyArray<string>;
}

export interface AuthenticationSessionsChangeEvent {
added: ReadonlyArray<string>;
removed: ReadonlyArray<string>;
changed: ReadonlyArray<string>;
}

export interface AuthenticationProviderInformation {
id: string;
label: string;
}
25 changes: 24 additions & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ import {
SelectionRange,
CallHierarchyDefinition,
CallHierarchyReference,
SearchInWorkspaceResult
SearchInWorkspaceResult,
AuthenticationSession,
AuthenticationSessionsChangeEvent,
AuthenticationProviderInformation
} from './plugin-api-rpc-model';
import { ExtPluginApi } from './plugin-ext-api-contribution';
import { KeysToAnyValues, KeysToKeysToAnyValue } from './types';
Expand Down Expand Up @@ -1450,6 +1453,7 @@ export interface ClipboardMain {
}

export const PLUGIN_RPC_CONTEXT = {
AUTHENTICATION_MAIN: <ProxyIdentifier<AuthenticationMain>>createProxyIdentifier<AuthenticationMain>('AuthenticationMain'),
COMMAND_REGISTRY_MAIN: <ProxyIdentifier<CommandRegistryMain>>createProxyIdentifier<CommandRegistryMain>('CommandRegistryMain'),
QUICK_OPEN_MAIN: createProxyIdentifier<QuickOpenMain>('QuickOpenMain'),
DIALOGS_MAIN: createProxyIdentifier<DialogsMain>('DialogsMain'),
Expand Down Expand Up @@ -1480,6 +1484,7 @@ export const PLUGIN_RPC_CONTEXT = {
};

export const MAIN_RPC_CONTEXT = {
AUTHENTICATION_EXT: createProxyIdentifier<AuthenticationExt>('AuthenticationExt'),
HOSTED_PLUGIN_MANAGER_EXT: createProxyIdentifier<PluginManagerExt>('PluginManagerExt'),
COMMAND_REGISTRY_EXT: createProxyIdentifier<CommandRegistryExt>('CommandRegistryExt'),
QUICK_OPEN_EXT: createProxyIdentifier<QuickOpenExt>('QuickOpenExt'),
Expand Down Expand Up @@ -1525,6 +1530,24 @@ export interface TasksMain {
$terminateTask(id: number): void;
}

export interface AuthenticationExt {
$getSessions(id: string): Promise<ReadonlyArray<AuthenticationSession>>;
$login(id: string, scopes: string[]): Promise<AuthenticationSession>;
$logout(id: string, sessionId: string): Promise<void>;
$onDidChangeAuthenticationSessions(id: string, label: string, event: AuthenticationSessionsChangeEvent): Promise<void>;
$onDidChangeAuthenticationProviders(added: AuthenticationProviderInformation[], removed: AuthenticationProviderInformation[]): Promise<void>;
}

export interface AuthenticationMain {
$registerAuthenticationProvider(id: string, label: string, supportsMultipleAccounts: boolean): void;
$unregisterAuthenticationProvider(id: string): void;
$getProviderIds(): Promise<string[]>;
$updateSessions(providerId: string, event: AuthenticationSessionsChangeEvent): void;
$getSession(providerId: string, scopes: string[], extensionId: string, extensionName: string,
options: { createIfNone?: boolean, clearSessionPreference?: boolean }): Promise<theia.AuthenticationSession | undefined>;
$logout(providerId: string, sessionId: string): Promise<void>;
}

export interface RawColorInfo {
color: [number, number, number, number];
range: Range;
Expand Down
Loading

0 comments on commit ecd7321

Please sign in to comment.