From 7d43835ea22286e207b999022eda8b950bc3ae32 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Tue, 8 Feb 2022 09:06:37 +1000 Subject: [PATCH] Update client for authService refactor (#2302) --- jslib | 2 +- src/background/main.background.ts | 20 ++++++++++++------- .../accounts/two-factor-options.component.ts | 8 ++++---- src/popup/accounts/two-factor.component.ts | 7 +++++-- src/popup/services/services.module.ts | 6 ++++++ 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/jslib b/jslib index e0cc754d6f..6b8508579f 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit e0cc754d6fe962a5e7eae6d1dead8b44606d4853 +Subproject commit 6b8508579f89b4c54afa6aab2b7155aac70fb8a9 diff --git a/src/background/main.background.ts b/src/background/main.background.ts index cbe5b136fc..45c5c0c562 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -32,6 +32,7 @@ import { SyncService } from "jslib-common/services/sync.service"; import { SystemService } from "jslib-common/services/system.service"; import { TokenService } from "jslib-common/services/token.service"; import { TotpService } from "jslib-common/services/totp.service"; +import { TwoFactorService } from "jslib-common/services/twoFactor.service"; import { UserVerificationService } from "jslib-common/services/userVerification.service"; import { WebCryptoFunctionService } from "jslib-common/services/webCryptoFunction.service"; @@ -66,6 +67,7 @@ import { SyncService as SyncServiceAbstraction } from "jslib-common/abstractions import { SystemService as SystemServiceAbstraction } from "jslib-common/abstractions/system.service"; import { TokenService as TokenServiceAbstraction } from "jslib-common/abstractions/token.service"; import { TotpService as TotpServiceAbstraction } from "jslib-common/abstractions/totp.service"; +import { TwoFactorService as TwoFactorServiceAbstraction } from "jslib-common/abstractions/twoFactor.service"; import { UserVerificationService as UserVerificationServiceAbstraction } from "jslib-common/abstractions/userVerification.service"; import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "jslib-common/abstractions/vaultTimeout.service"; @@ -141,6 +143,7 @@ export default class MainBackground { providerService: ProviderServiceAbstraction; keyConnectorService: KeyConnectorServiceAbstraction; userVerificationService: UserVerificationServiceAbstraction; + twoFactorService: TwoFactorServiceAbstraction; onUpdatedRan: boolean; onReplacedRan: boolean; @@ -264,7 +267,8 @@ export default class MainBackground { this.apiService, this.tokenService, this.logService, - this.organizationService + this.organizationService, + this.cryptoFunctionService ); const vaultTimeoutServiceCallbacks = { @@ -345,7 +349,8 @@ export default class MainBackground { this.folderService, this.cipherService, this.apiService, - this.cryptoService + this.cryptoService, + this.cryptoFunctionService ); this.notificationsService = new NotificationsService( this.syncService, @@ -451,6 +456,8 @@ export default class MainBackground { ); this.windowsBackground = new WindowsBackground(this); + this.twoFactorService = new TwoFactorService(this.i18nService, this.platformUtilsService); + const that = this; const backgroundMessagingService = new (class extends MessagingServiceAbstraction { // AuthService should send the messages to the background not popup. @@ -464,15 +471,13 @@ export default class MainBackground { this.apiService, this.tokenService, this.appIdService, - this.i18nService, this.platformUtilsService, backgroundMessagingService, - this.vaultTimeoutService, this.logService, - this.cryptoFunctionService, this.keyConnectorService, this.environmentService, - this.stateService + this.stateService, + this.twoFactorService ); } @@ -481,7 +486,6 @@ export default class MainBackground { await this.stateService.init(); - (this.authService as AuthService).init(); await (this.vaultTimeoutService as VaultTimeoutService).init(true); await (this.i18nService as I18nService).init(); await (this.eventService as EventService).init(true); @@ -489,6 +493,8 @@ export default class MainBackground { await this.notificationBackground.init(); await this.commandsBackground.init(); + this.twoFactorService.init(); + await this.tabsBackground.init(); await this.contextMenusBackground.init(); await this.idleBackground.init(); diff --git a/src/popup/accounts/two-factor-options.component.ts b/src/popup/accounts/two-factor-options.component.ts index 3c05ec0e43..b3ada8e10d 100644 --- a/src/popup/accounts/two-factor-options.component.ts +++ b/src/popup/accounts/two-factor-options.component.ts @@ -1,9 +1,9 @@ import { Component } from "@angular/core"; import { Router } from "@angular/router"; -import { AuthService } from "jslib-common/abstractions/auth.service"; import { I18nService } from "jslib-common/abstractions/i18n.service"; import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; +import { TwoFactorService } from "jslib-common/abstractions/twoFactor.service"; import { TwoFactorOptionsComponent as BaseTwoFactorOptionsComponent } from "jslib-angular/components/two-factor-options.component"; @@ -13,17 +13,17 @@ import { TwoFactorOptionsComponent as BaseTwoFactorOptionsComponent } from "jsli }) export class TwoFactorOptionsComponent extends BaseTwoFactorOptionsComponent { constructor( - authService: AuthService, + twoFactorService: TwoFactorService, router: Router, i18nService: I18nService, platformUtilsService: PlatformUtilsService ) { - super(authService, router, i18nService, platformUtilsService, window); + super(twoFactorService, router, i18nService, platformUtilsService, window); } choose(p: any) { super.choose(p); - this.authService.selectedTwoFactorProviderType = p.type; + this.twoFactorService.setSelectedProvider(p.type); this.router.navigate(["2fa"]); } } diff --git a/src/popup/accounts/two-factor.component.ts b/src/popup/accounts/two-factor.component.ts index 92b0f1d993..6267d58e06 100644 --- a/src/popup/accounts/two-factor.component.ts +++ b/src/popup/accounts/two-factor.component.ts @@ -14,6 +14,7 @@ import { MessagingService } from "jslib-common/abstractions/messaging.service"; import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; import { StateService } from "jslib-common/abstractions/state.service"; import { SyncService } from "jslib-common/abstractions/sync.service"; +import { TwoFactorService } from "jslib-common/abstractions/twoFactor.service"; import { TwoFactorComponent as BaseTwoFactorComponent } from "jslib-angular/components/two-factor.component"; @@ -43,7 +44,8 @@ export class TwoFactorComponent extends BaseTwoFactorComponent { stateService: StateService, route: ActivatedRoute, private messagingService: MessagingService, - logService: LogService + logService: LogService, + twoFactorService: TwoFactorService ) { super( authService, @@ -55,7 +57,8 @@ export class TwoFactorComponent extends BaseTwoFactorComponent { environmentService, stateService, route, - logService + logService, + twoFactorService ); super.onSuccessfulLogin = () => { return syncService.fullSync(true); diff --git a/src/popup/services/services.module.ts b/src/popup/services/services.module.ts index 1ace27669a..511a547f70 100644 --- a/src/popup/services/services.module.ts +++ b/src/popup/services/services.module.ts @@ -44,6 +44,7 @@ import { StorageService as StorageServiceAbstraction } from "jslib-common/abstra import { SyncService } from "jslib-common/abstractions/sync.service"; import { TokenService } from "jslib-common/abstractions/token.service"; import { TotpService } from "jslib-common/abstractions/totp.service"; +import { TwoFactorService } from "jslib-common/abstractions/twoFactor.service"; import { UserVerificationService } from "jslib-common/abstractions/userVerification.service"; import { VaultTimeoutService } from "jslib-common/abstractions/vaultTimeout.service"; @@ -147,6 +148,11 @@ export function initFactory( DebounceNavigationService, PopupUtilsService, { provide: MessagingService, useClass: BrowserMessagingService }, + { + provide: TwoFactorService, + useFactory: getBgService("twoFactorService"), + deps: [], + }, { provide: AuthServiceAbstraction, useFactory: getBgService("authService"),