rename and pass environment service

This commit is contained in:
Sandeep Somavarapu 2020-08-20 10:46:56 +02:00
parent 780fb8c8e8
commit 79e9ee33c9
4 changed files with 18 additions and 17 deletions

View file

@ -28,7 +28,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { Codicon } from 'vs/base/common/codicons';
import { isMacintosh } from 'vs/base/common/platform';
import { getAuthenticationSession, IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService';
import { getCurrentAuthenticationSessionInfo, IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService';
import { AuthenticationSession } from 'vs/editor/common/modes';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { ActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
@ -180,7 +180,7 @@ export class AccountsActionViewItem extends ActivityActionViewItem {
const result = await Promise.all(allSessions);
let menus: IAction[] = [];
const authenticationSession = this.environmentService.options?.credentialsProvider ? await getAuthenticationSession(this.environmentService.options?.credentialsProvider, this.productService) : undefined;
const authenticationSession = this.environmentService.options?.credentialsProvider ? await getCurrentAuthenticationSessionInfo(this.environmentService, this.productService) : undefined;
result.forEach(sessionInfo => {
const providerDisplayName = this.authenticationService.getLabel(sessionInfo.providerId);
Object.keys(sessionInfo.sessions).forEach(accountName => {

View file

@ -16,22 +16,23 @@ import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { ICredentialsProvider } from 'vs/platform/credentials/common/credentials';
import { IProductService } from 'vs/platform/product/common/productService';
import { isString } from 'vs/base/common/types';
export function getAuthenticationProviderActivationEvent(id: string): string { return `onAuthenticationRequest:${id}`; }
export async function getAuthenticationSession(credentialsProvider: ICredentialsProvider, productService: IProductService): Promise<{ id: string, accessToken: string, providerId: string } | undefined> {
const authenticationSessionValue = await credentialsProvider.getPassword(`${productService.urlProtocol}.login`, 'account');
if (authenticationSessionValue) {
const authenticationSession: { id: string, accessToken: string, providerId: string } = JSON.parse(authenticationSessionValue);
if (authenticationSession
&& isString(authenticationSession.id)
&& isString(authenticationSession.accessToken)
&& isString(authenticationSession.providerId)
) {
return authenticationSession;
export async function getCurrentAuthenticationSessionInfo(environmentService: IWorkbenchEnvironmentService, productService: IProductService): Promise<{ id: string, accessToken: string, providerId: string } | undefined> {
if (environmentService.options?.credentialsProvider) {
const authenticationSessionValue = await environmentService.options.credentialsProvider.getPassword(`${productService.urlProtocol}.login`, 'account');
if (authenticationSessionValue) {
const authenticationSession: { id: string, accessToken: string, providerId: string } = JSON.parse(authenticationSessionValue);
if (authenticationSession
&& isString(authenticationSession.id)
&& isString(authenticationSession.accessToken)
&& isString(authenticationSession.providerId)
) {
return authenticationSession;
}
}
}
return undefined;

View file

@ -19,7 +19,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
import { IRequestService } from 'vs/platform/request/common/request';
import { CONFIGURATION_SYNC_STORE_KEY, IUserDataSyncStoreClient, SyncResource } from 'vs/platform/userDataSync/common/userDataSync';
import { URI } from 'vs/base/common/uri';
import { getAuthenticationSession } from 'vs/workbench/services/authentication/browser/authenticationService';
import { getCurrentAuthenticationSessionInfo } from 'vs/workbench/services/authentication/browser/authenticationService';
import { getSyncAreaLabel } from 'vs/workbench/services/userDataSync/common/userDataSync';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions } from 'vs/workbench/common/contributions';
import { Registry } from 'vs/platform/registry/common/platform';
@ -87,7 +87,7 @@ export class UserDataInitializationService implements IUserDataInitializationSer
let authenticationSession;
try {
authenticationSession = await getAuthenticationSession(this.environmentService.options.credentialsProvider, this.productService);
authenticationSession = await getCurrentAuthenticationSessionInfo(this.environmentService, this.productService);
} catch (error) {
this.logService.error(error);
}

View file

@ -11,7 +11,7 @@ import { AuthenticationSession, AuthenticationSessionsChangeEvent } from 'vs/edi
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Emitter, Event } from 'vs/base/common/event';
import { flatten, equals } from 'vs/base/common/arrays';
import { getAuthenticationProviderActivationEvent, getAuthenticationSession, IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService';
import { getAuthenticationProviderActivationEvent, getCurrentAuthenticationSessionInfo, IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService';
import { IUserDataSyncAccountService } from 'vs/platform/userDataSync/common/userDataSyncAccount';
import { IQuickInputService, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { IStorageService, IWorkspaceStorageChangeEvent, StorageScope } from 'vs/platform/storage/common/storage';
@ -153,7 +153,7 @@ export class UserDataSyncWorkbenchService extends Disposable implements IUserDat
}
private async initialize(): Promise<void> {
const authenticationSession = this.environmentService.options?.credentialsProvider ? await getAuthenticationSession(this.environmentService.options?.credentialsProvider, this.productService) : undefined;
const authenticationSession = this.environmentService.options?.credentialsProvider ? await getCurrentAuthenticationSessionInfo(this.environmentService, this.productService) : undefined;
if (this.currentSessionId === undefined && this.useWorkbenchSessionId && (authenticationSession?.id || this.environmentService.options?.authenticationSessionId)) {
this.currentSessionId = authenticationSession?.id || this.environmentService.options?.authenticationSessionId;
this.useWorkbenchSessionId = false;