From d9d910325ae44e5703fd9afef2cb9d5b92e72db6 Mon Sep 17 00:00:00 2001 From: Alec Rippberger Date: Wed, 5 Mar 2025 12:31:54 -0600 Subject: [PATCH] Add web and desktop noop cache services --- .../src/app/services/services.module.ts | 7 +++++ .../desktop-two-factor-form-cache.service.ts | 30 +++++++++++++++++++ .../src/auth/two-factor-v1.component.ts | 3 ++ .../core/services/two-factor-auth/index.ts | 1 + .../web-two-factor-form-cache.service.ts | 30 +++++++++++++++++++ .../src/app/auth/two-factor-v1.component.ts | 3 ++ apps/web/src/app/core/core.module.ts | 7 +++++ 7 files changed, 81 insertions(+) create mode 100644 apps/desktop/src/auth/services/desktop-two-factor-form-cache.service.ts create mode 100644 apps/web/src/app/auth/core/services/two-factor-auth/web-two-factor-form-cache.service.ts diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index 23a207c8cb4..afa38b46a00 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -27,6 +27,7 @@ import { SsoComponentService, DefaultSsoComponentService, TwoFactorAuthDuoComponentService, + TwoFactorFormCacheService, } from "@bitwarden/auth/angular"; import { InternalUserDecryptionOptionsServiceAbstraction, @@ -107,6 +108,7 @@ import { LockComponentService } from "@bitwarden/key-management-ui"; import { DesktopLoginApprovalComponentService } from "../../auth/login/desktop-login-approval-component.service"; import { DesktopLoginComponentService } from "../../auth/login/desktop-login-component.service"; import { DesktopTwoFactorAuthDuoComponentService } from "../../auth/services/desktop-two-factor-auth-duo-component.service"; +import { DesktopTwoFactorFormCacheService } from "../../auth/services/desktop-two-factor-form-cache.service"; import { DesktopAutofillSettingsService } from "../../autofill/services/desktop-autofill-settings.service"; import { DesktopAutofillService } from "../../autofill/services/desktop-autofill.service"; import { DesktopFido2UserInterfaceService } from "../../autofill/services/desktop-fido2-user-interface.service"; @@ -412,6 +414,11 @@ const safeProviders: SafeProvider[] = [ PlatformUtilsServiceAbstraction, ], }), + safeProvider({ + provide: TwoFactorFormCacheService, + useClass: DesktopTwoFactorFormCacheService, + deps: [], + }), safeProvider({ provide: SdkClientFactory, useClass: flagEnabled("sdk") ? DefaultSdkClientFactory : NoopSdkClientFactory, diff --git a/apps/desktop/src/auth/services/desktop-two-factor-form-cache.service.ts b/apps/desktop/src/auth/services/desktop-two-factor-form-cache.service.ts new file mode 100644 index 00000000000..c031c23dc1f --- /dev/null +++ b/apps/desktop/src/auth/services/desktop-two-factor-form-cache.service.ts @@ -0,0 +1,30 @@ +import { Injectable } from "@angular/core"; +import { Observable, of } from "rxjs"; + +import { TwoFactorFormCacheService, TwoFactorFormData } from "@bitwarden/auth/angular"; + +/** + * No-op implementation of TwoFactorFormCacheService for desktop + */ +@Injectable() +export class DesktopTwoFactorFormCacheService extends TwoFactorFormCacheService { + constructor() { + super(); + } + + isEnabled$(): Observable { + return of(false); + } + + formData$(): Observable { + return of(null); + } + + async saveFormData(): Promise { + // No-op + } + + async clearFormData(): Promise { + // No-op + } +} diff --git a/apps/desktop/src/auth/two-factor-v1.component.ts b/apps/desktop/src/auth/two-factor-v1.component.ts index 26a6f81b88c..db1bdc4b76c 100644 --- a/apps/desktop/src/auth/two-factor-v1.component.ts +++ b/apps/desktop/src/auth/two-factor-v1.component.ts @@ -29,6 +29,7 @@ import { StateService } from "@bitwarden/common/platform/abstractions/state.serv import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { ToastService } from "@bitwarden/components"; +import { DesktopTwoFactorFormCacheService } from "./services/desktop-two-factor-form-cache.service"; import { TwoFactorOptionsComponentV1 } from "./two-factor-options-v1.component"; const BroadcasterSubscriptionId = "TwoFactorComponent"; @@ -69,6 +70,7 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnDe accountService: AccountService, toastService: ToastService, @Inject(WINDOW) protected win: Window, + twoFactorFormCacheService: DesktopTwoFactorFormCacheService, ) { super( loginStrategyService, @@ -90,6 +92,7 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnDe masterPasswordService, accountService, toastService, + twoFactorFormCacheService, ); this.onSuccessfulLogin = async () => { // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. diff --git a/apps/web/src/app/auth/core/services/two-factor-auth/index.ts b/apps/web/src/app/auth/core/services/two-factor-auth/index.ts index ba2697fdee4..2d20e5fe02a 100644 --- a/apps/web/src/app/auth/core/services/two-factor-auth/index.ts +++ b/apps/web/src/app/auth/core/services/two-factor-auth/index.ts @@ -1,2 +1,3 @@ export * from "./web-two-factor-auth-component.service"; export * from "./web-two-factor-auth-duo-component.service"; +export * from "./web-two-factor-form-cache.service"; diff --git a/apps/web/src/app/auth/core/services/two-factor-auth/web-two-factor-form-cache.service.ts b/apps/web/src/app/auth/core/services/two-factor-auth/web-two-factor-form-cache.service.ts new file mode 100644 index 00000000000..1c2272a0b2e --- /dev/null +++ b/apps/web/src/app/auth/core/services/two-factor-auth/web-two-factor-form-cache.service.ts @@ -0,0 +1,30 @@ +import { Injectable } from "@angular/core"; +import { Observable, of } from "rxjs"; + +import { TwoFactorFormCacheService, TwoFactorFormData } from "@bitwarden/auth/angular"; + +/** + * No-op implementation of TwoFactorFormCacheService for web app + */ +@Injectable() +export class WebTwoFactorFormCacheService extends TwoFactorFormCacheService { + constructor() { + super(); + } + + isEnabled$(): Observable { + return of(false); + } + + formData$(): Observable { + return of(null); + } + + async saveFormData(): Promise { + // No-op + } + + async clearFormData(): Promise { + // No-op + } +} diff --git a/apps/web/src/app/auth/two-factor-v1.component.ts b/apps/web/src/app/auth/two-factor-v1.component.ts index adaa735eca7..ec1016bcdef 100644 --- a/apps/web/src/app/auth/two-factor-v1.component.ts +++ b/apps/web/src/app/auth/two-factor-v1.component.ts @@ -7,6 +7,7 @@ import { Subject, takeUntil, lastValueFrom } from "rxjs"; import { TwoFactorComponentV1 as BaseTwoFactorComponent } from "@bitwarden/angular/auth/components/two-factor-v1.component"; import { WINDOW } from "@bitwarden/angular/services/injection-tokens"; +import { TwoFactorFormCacheService } from "@bitwarden/auth/angular"; import { LoginStrategyServiceAbstraction, LoginEmailServiceAbstraction, @@ -74,6 +75,7 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnIn toastService: ToastService, private formBuilder: FormBuilder, @Inject(WINDOW) protected win: Window, + twoFactorFormCacheService: TwoFactorFormCacheService, ) { super( loginStrategyService, @@ -95,6 +97,7 @@ export class TwoFactorComponentV1 extends BaseTwoFactorComponent implements OnIn masterPasswordService, accountService, toastService, + twoFactorFormCacheService, ); this.onSuccessfulLoginNavigate = this.goAfterLogIn; } diff --git a/apps/web/src/app/core/core.module.ts b/apps/web/src/app/core/core.module.ts index c835e504b5a..273bbefd566 100644 --- a/apps/web/src/app/core/core.module.ts +++ b/apps/web/src/app/core/core.module.ts @@ -35,6 +35,7 @@ import { LoginDecryptionOptionsService, TwoFactorAuthComponentService, TwoFactorAuthDuoComponentService, + TwoFactorFormCacheService, } from "@bitwarden/auth/angular"; import { InternalUserDecryptionOptionsServiceAbstraction, @@ -117,6 +118,7 @@ import { WebTwoFactorAuthDuoComponentService, } from "../auth"; import { WebSsoComponentService } from "../auth/core/services/login/web-sso-component.service"; +import { WebTwoFactorFormCacheService } from "../auth/core/services/two-factor-auth/web-two-factor-form-cache.service"; import { AcceptOrganizationInviteService } from "../auth/organization-invite/accept-organization.service"; import { HtmlStorageService } from "../core/html-storage.service"; import { I18nService } from "../core/i18n.service"; @@ -274,6 +276,11 @@ const safeProviders: SafeProvider[] = [ useClass: WebTwoFactorAuthComponentService, deps: [], }), + safeProvider({ + provide: TwoFactorFormCacheService, + useClass: WebTwoFactorFormCacheService, + deps: [], + }), safeProvider({ provide: SetPasswordJitService, useClass: WebSetPasswordJitService,