From 9fcc4f0543fce95c90b10616fff13e3a273d0457 Mon Sep 17 00:00:00 2001 From: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:43:17 -0500 Subject: [PATCH] PM-13659 - 2FA Timeout Log All the things (#12275) --- .../auth/components/two-factor.component.ts | 10 ++++++ .../abstractions/login-strategy.service.ts | 2 ++ .../login-strategy.service.ts | 36 ++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/libs/angular/src/auth/components/two-factor.component.ts b/libs/angular/src/auth/components/two-factor.component.ts index 33269e28e9..f484ccd1e8 100644 --- a/libs/angular/src/auth/components/two-factor.component.ts +++ b/libs/angular/src/auth/components/two-factor.component.ts @@ -102,10 +102,20 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI super(environmentService, i18nService, platformUtilsService, toastService); this.webAuthnSupported = this.platformUtilsService.supportsWebAuthn(win); + this.logService.info( + "Subscribing to timeout on LoginStrategyService with service id: " + + this.loginStrategyService.id, + ); + // Add subscription to twoFactorTimeout$ and navigate to twoFactorTimeoutRoute if expired this.loginStrategyService.twoFactorTimeout$ .pipe(takeUntilDestroyed()) .subscribe(async (expired) => { + this.logService.info( + "Received emission from LoginStrategyService.twoFactorTimeout$ with service id: " + + this.loginStrategyService.id, + ); + if (!expired) { return; } diff --git a/libs/auth/src/common/abstractions/login-strategy.service.ts b/libs/auth/src/common/abstractions/login-strategy.service.ts index e86cd6b0b0..89e8491b27 100644 --- a/libs/auth/src/common/abstractions/login-strategy.service.ts +++ b/libs/auth/src/common/abstractions/login-strategy.service.ts @@ -14,6 +14,8 @@ import { } from "../models/domain/login-credentials"; export abstract class LoginStrategyServiceAbstraction { + id: string; + /** * The current strategy being used to authenticate. * Emits null if the session has timed out. diff --git a/libs/auth/src/common/services/login-strategies/login-strategy.service.ts b/libs/auth/src/common/services/login-strategies/login-strategy.service.ts index 1d5001f1f0..0c857cf7cc 100644 --- a/libs/auth/src/common/services/login-strategies/login-strategy.service.ts +++ b/libs/auth/src/common/services/login-strategies/login-strategy.service.ts @@ -7,6 +7,7 @@ import { shareReplay, Subscription, BehaviorSubject, + tap, } from "rxjs"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; @@ -31,6 +32,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service" import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; +import { Utils } from "@bitwarden/common/platform/misc/utils"; import { TaskSchedulerService, ScheduledTaskNames } from "@bitwarden/common/platform/scheduling"; import { GlobalState, GlobalStateProvider } from "@bitwarden/common/platform/state"; import { DeviceTrustServiceAbstraction } from "@bitwarden/common/src/auth/abstractions/device-trust.service.abstraction"; @@ -81,7 +83,36 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction { private authRequestPushNotificationState: GlobalState; private twoFactorTimeoutSubject = new BehaviorSubject(false); - twoFactorTimeout$: Observable = this.twoFactorTimeoutSubject.asObservable(); + twoFactorTimeout$: Observable = this.twoFactorTimeoutSubject.asObservable().pipe( + // line 87 is the tap? + tap({ + next: (value) => { + this.logService.info( + `LoginStrategyService.twoFactorTimeout$ with service id: ${this.id} emmitted value: ${value}`, + ); + }, + error: (error: unknown) => { + this.logService.error( + `LoginStrategyService.twoFactorTimeout$ with service id: ${this.id} errored with error: ${JSON.stringify(error)}`, + ); + }, + finalize: () => { + this.logService.info( + `LoginStrategyService.twoFactorTimeout$ with service id: ${this.id} finalized`, + ); + }, + complete: () => { + this.logService.info( + `LoginStrategyService.twoFactorTimeout$ with service id: ${this.id} completed`, + ); + }, + subscribe: () => { + this.logService.info( + `LoginStrategyService.twoFactorTimeout$ with service id: ${this.id} subscribed`, + ); + }, + }), + ); private loginStrategy$: Observable< | UserApiLoginStrategy @@ -94,6 +125,8 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction { currentAuthType$: Observable; + id: string = Utils.newGuid(); + constructor( protected accountService: AccountService, protected masterPasswordService: InternalMasterPasswordServiceAbstraction, @@ -131,6 +164,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction { this.taskSchedulerService.registerTaskHandler( ScheduledTaskNames.loginStrategySessionTimeout, async () => { + this.logService.info("Timeout executing for LoginStrategyService with id: " + this.id); this.authnSessionTimeoutExecutor(async () => { this.twoFactorTimeoutSubject.next(true); try {