diff --git a/src/vs/workbench/api/browser/mainThreadAuthentication.ts b/src/vs/workbench/api/browser/mainThreadAuthentication.ts index 09009ba5974..f6286c8656d 100644 --- a/src/vs/workbench/api/browser/mainThreadAuthentication.ts +++ b/src/vs/workbench/api/browser/mainThreadAuthentication.ts @@ -268,7 +268,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu async $getSession(providerId: string, scopes: string[], extensionId: string, extensionName: string, options: { createIfNone: boolean, clearSessionPreference: boolean }): Promise { const orderedScopes = scopes.sort().join(' '); - const sessions = (await this.authenticationService.getSessions(providerId)).filter(session => session.scopes.slice().sort().join(' ') === orderedScopes); + const sessions = (await this.authenticationService.getSessions(providerId, true)).filter(session => session.scopes.slice().sort().join(' ') === orderedScopes); const silent = !options.createIfNone; let session: modes.AuthenticationSession | undefined; @@ -300,7 +300,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu throw new Error('User did not consent to login.'); } - session = await this.authenticationService.login(providerId, scopes); + session = await this.authenticationService.login(providerId, scopes, true); await this.setTrustedExtensionAndAccountPreference(providerId, session.account.label, extensionId, extensionName, session.id); } else { await this.authenticationService.requestNewSession(providerId, scopes, extensionId, extensionName); diff --git a/src/vs/workbench/services/authentication/browser/authenticationService.ts b/src/vs/workbench/services/authentication/browser/authenticationService.ts index 2c97d497e03..b91263aa5c6 100644 --- a/src/vs/workbench/services/authentication/browser/authenticationService.ts +++ b/src/vs/workbench/services/authentication/browser/authenticationService.ts @@ -22,7 +22,7 @@ import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/exte import { IJSONSchema } from 'vs/base/common/jsonSchema'; import { flatten } from 'vs/base/common/arrays'; import { isFalsyOrWhitespace } from 'vs/base/common/strings'; -import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; +import { ActivationKind, IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { Severity } from 'vs/platform/notification/common/notification'; import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; @@ -124,10 +124,10 @@ export interface IAuthenticationService { declaredProviders: AuthenticationProviderInformation[]; readonly onDidChangeDeclaredProviders: Event; - getSessions(providerId: string): Promise>; + getSessions(providerId: string, activateImmediate?: boolean): Promise>; getLabel(providerId: string): string; supportsMultipleAccounts(providerId: string): boolean; - login(providerId: string, scopes: string[]): Promise; + login(providerId: string, scopes: string[], activateImmediate?: boolean): Promise; logout(providerId: string, sessionId: string): Promise; manageTrustedExtensionsForAccount(providerId: string, accountName: string): Promise; @@ -693,8 +693,8 @@ export class AuthenticationService extends Disposable implements IAuthentication } } - private async tryActivateProvider(providerId: string): Promise { - await this.extensionService.activateByEvent(getAuthenticationProviderActivationEvent(providerId)); + private async tryActivateProvider(providerId: string, activateImmediate: boolean): Promise { + await this.extensionService.activateByEvent(getAuthenticationProviderActivationEvent(providerId), activateImmediate ? ActivationKind.Immediate : ActivationKind.Normal); let provider = this._authenticationProviders.get(providerId); if (provider) { return provider; @@ -724,18 +724,18 @@ export class AuthenticationService extends Disposable implements IAuthentication return Promise.race([didRegister, didTimeout]); } - async getSessions(id: string): Promise> { + async getSessions(id: string, activateImmediate: boolean = false): Promise> { try { - const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id); + const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id, activateImmediate); return await authProvider.getSessions(); } catch (_) { throw new Error(`No authentication provider '${id}' is currently registered.`); } } - async login(id: string, scopes: string[]): Promise { + async login(id: string, scopes: string[], activateImmediate: boolean = false): Promise { try { - const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id); + const authProvider = this._authenticationProviders.get(id) || await this.tryActivateProvider(id, activateImmediate); return await authProvider.login(scopes); } catch (_) { throw new Error(`No authentication provider '${id}' is currently registered.`);