diff --git a/apps/browser/src/auth/popup/settings/account-security.component.spec.ts b/apps/browser/src/auth/popup/settings/account-security.component.spec.ts index d1380f5eae0..3f5a03cc391 100644 --- a/apps/browser/src/auth/popup/settings/account-security.component.spec.ts +++ b/apps/browser/src/auth/popup/settings/account-security.component.spec.ts @@ -7,7 +7,7 @@ import { firstValueFrom, of, BehaviorSubject } from "rxjs"; import { CollectionService } from "@bitwarden/admin-console/common"; import { NudgesService } from "@bitwarden/angular/vault"; -import { LockService } from "@bitwarden/auth/common"; +import { LockService, LogoutService } from "@bitwarden/auth/common"; import { AutomaticUserConfirmationService } from "@bitwarden/auto-confirm"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; @@ -75,6 +75,7 @@ describe("AccountSecurityComponent", () => { const dialogService = mock(); const keyService = mock(); const lockService = mock(); + const logoutService = mock(); const policyService = mock(); const phishingDetectionSettingsService = mock(); const pinServiceAbstraction = mock(); @@ -109,6 +110,7 @@ describe("AccountSecurityComponent", () => { { provide: I18nService, useValue: mockI18nService }, { provide: KeyService, useValue: keyService }, { provide: LockService, useValue: lockService }, + { provide: LogoutService, useValue: logoutService }, { provide: LogService, useValue: mock() }, { provide: MessageSender, useValue: mock() }, { provide: NudgesService, useValue: vaultNudgesService }, diff --git a/apps/browser/src/auth/popup/settings/account-security.component.ts b/apps/browser/src/auth/popup/settings/account-security.component.ts index 6a3378670bf..fcaeccce9a1 100644 --- a/apps/browser/src/auth/popup/settings/account-security.component.ts +++ b/apps/browser/src/auth/popup/settings/account-security.component.ts @@ -25,7 +25,7 @@ import { JslibModule } from "@bitwarden/angular/jslib.module"; import { NudgesService, NudgeType } from "@bitwarden/angular/vault"; import { SpotlightComponent } from "@bitwarden/angular/vault/components/spotlight/spotlight.component"; import { FingerprintDialogComponent } from "@bitwarden/auth/angular"; -import { LockService } from "@bitwarden/auth/common"; +import { LockService, LogoutService } from "@bitwarden/auth/common"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; import { PolicyType } from "@bitwarden/common/admin-console/enums"; import { getFirstPolicy } from "@bitwarden/common/admin-console/services/policy/default-policy.service"; @@ -174,6 +174,7 @@ export class AccountSecurityComponent implements OnInit, OnDestroy { private validationService: ValidationService, private logService: LogService, private phishingDetectionSettingsService: PhishingDetectionSettingsServiceAbstraction, + private logoutService: LogoutService, ) { this.consolidatedSessionTimeoutComponent$ = this.configService.getFeatureFlag$( FeatureFlag.ConsolidatedSessionTimeoutComponent, @@ -751,8 +752,8 @@ export class AccountSecurityComponent implements OnInit, OnDestroy { }); const userId = (await firstValueFrom(this.accountService.activeAccount$))?.id; - if (confirmed) { - this.messagingService.send("logout", { userId: userId }); + if (confirmed && userId) { + await this.logoutService.logout(userId, "userInitiated"); } } diff --git a/apps/web/src/app/auth/settings/account/change-email.component.spec.ts b/apps/web/src/app/auth/settings/account/change-email.component.spec.ts index 56f2bfe2112..f244be8f5a2 100644 --- a/apps/web/src/app/auth/settings/account/change-email.component.spec.ts +++ b/apps/web/src/app/auth/settings/account/change-email.component.spec.ts @@ -4,13 +4,13 @@ import mock, { MockProxy } from "jest-mock-extended/lib/Mock"; import { firstValueFrom, of } from "rxjs"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { LogoutService } from "@bitwarden/auth/common"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-provider-type"; import { TwoFactorProviderResponse } from "@bitwarden/common/auth/models/response/two-factor-provider.response"; import { TwoFactorService } from "@bitwarden/common/auth/two-factor"; import { ListResponse } from "@bitwarden/common/models/response/list.response"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/spec"; import { UserId } from "@bitwarden/common/types/guid"; import { ToastService } from "@bitwarden/components"; @@ -43,7 +43,7 @@ describe("ChangeEmailComponent", () => { { provide: TwoFactorService, useValue: twoFactorService }, { provide: I18nService, useValue: { t: (key: string) => key } }, { provide: KeyService, useValue: keyService }, - { provide: MessagingService, useValue: mock() }, + { provide: LogoutService, useValue: mock() }, { provide: KdfConfigService, useValue: kdfConfigService }, { provide: ToastService, useValue: mock() }, { provide: FormBuilder, useClass: FormBuilder }, diff --git a/apps/web/src/app/auth/settings/account/change-email.component.ts b/apps/web/src/app/auth/settings/account/change-email.component.ts index 3daf2240fb2..1520369dec9 100644 --- a/apps/web/src/app/auth/settings/account/change-email.component.ts +++ b/apps/web/src/app/auth/settings/account/change-email.component.ts @@ -3,6 +3,7 @@ import { FormBuilder, Validators } from "@angular/forms"; import { firstValueFrom } from "rxjs"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { LogoutService } from "@bitwarden/auth/common"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-provider-type"; import { EmailTokenRequest } from "@bitwarden/common/auth/models/request/email-token.request"; @@ -10,7 +11,6 @@ import { EmailRequest } from "@bitwarden/common/auth/models/request/email.reques import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { TwoFactorService } from "@bitwarden/common/auth/two-factor"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { UserId } from "@bitwarden/common/types/guid"; import { ToastService } from "@bitwarden/components"; import { KdfConfigService, KeyService } from "@bitwarden/key-management"; @@ -43,10 +43,10 @@ export class ChangeEmailComponent implements OnInit { private twoFactorService: TwoFactorService, private i18nService: I18nService, private keyService: KeyService, - private messagingService: MessagingService, private formBuilder: FormBuilder, private kdfConfigService: KdfConfigService, private toastService: ToastService, + private logoutService: LogoutService, ) {} async ngOnInit() { @@ -132,7 +132,7 @@ export class ChangeEmailComponent implements OnInit { title: this.i18nService.t("emailChanged"), message: this.i18nService.t("logBackIn"), }); - this.messagingService.send("logout"); + await this.logoutService.logout(this.userId, "emailChanged"); } }; diff --git a/apps/web/src/app/auth/settings/account/deauthorize-sessions.component.ts b/apps/web/src/app/auth/settings/account/deauthorize-sessions.component.ts index b792963ae9b..8fbd1d12754 100644 --- a/apps/web/src/app/auth/settings/account/deauthorize-sessions.component.ts +++ b/apps/web/src/app/auth/settings/account/deauthorize-sessions.component.ts @@ -1,13 +1,16 @@ import { Component } from "@angular/core"; import { FormBuilder } from "@angular/forms"; +import { firstValueFrom } from "rxjs"; import { UserVerificationFormInputComponent } from "@bitwarden/auth/angular"; +import { LogoutService } from "@bitwarden/auth/common"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction"; +import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { Verification } from "@bitwarden/common/auth/types/verification"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { DialogService, ToastService } from "@bitwarden/components"; import { SharedModule } from "../../../shared"; @@ -29,9 +32,10 @@ export class DeauthorizeSessionsComponent { private i18nService: I18nService, private formBuilder: FormBuilder, private userVerificationService: UserVerificationService, - private messagingService: MessagingService, private logService: LogService, private toastService: ToastService, + private logoutService: LogoutService, + private accountService: AccountService, ) {} submit = async () => { @@ -44,7 +48,8 @@ export class DeauthorizeSessionsComponent { title: this.i18nService.t("sessionsDeauthorized"), message: this.i18nService.t("logBackIn"), }); - this.messagingService.send("logout"); + const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); + await this.logoutService.logout(userId, "sessionsDeauthorized"); } catch (e) { this.logService.error(e); } diff --git a/apps/web/src/app/key-management/change-kdf/change-kdf-confirmation.component.spec.ts b/apps/web/src/app/key-management/change-kdf/change-kdf-confirmation.component.spec.ts index 2c2caba7b3a..6ceb5aff819 100644 --- a/apps/web/src/app/key-management/change-kdf/change-kdf-confirmation.component.spec.ts +++ b/apps/web/src/app/key-management/change-kdf/change-kdf-confirmation.component.spec.ts @@ -3,11 +3,11 @@ import { FormControl } from "@angular/forms"; import { mock, MockProxy } from "jest-mock-extended"; import { of } from "rxjs"; +import { LogoutService } from "@bitwarden/auth/common"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { ChangeKdfService } from "@bitwarden/common/key-management/kdf/change-kdf.service.abstraction"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/spec"; import { UserId } from "@bitwarden/common/types/guid"; import { DIALOG_DATA, DialogRef, ToastService } from "@bitwarden/components"; @@ -23,7 +23,7 @@ describe("ChangeKdfConfirmationComponent", () => { // Mock Services let mockI18nService: MockProxy; - let mockMessagingService: MockProxy; + let mockLogoutService: MockProxy; let mockToastService: MockProxy; let mockDialogRef: MockProxy>; let mockConfigService: MockProxy; @@ -38,7 +38,7 @@ describe("ChangeKdfConfirmationComponent", () => { beforeEach(() => { mockI18nService = mock(); - mockMessagingService = mock(); + mockLogoutService = mock(); mockToastService = mock(); mockDialogRef = mock>(); mockConfigService = mock(); @@ -60,7 +60,7 @@ describe("ChangeKdfConfirmationComponent", () => { imports: [SharedModule], providers: [ { provide: I18nService, useValue: mockI18nService }, - { provide: MessagingService, useValue: mockMessagingService }, + { provide: LogoutService, useValue: mockLogoutService }, { provide: AccountService, useValue: accountService }, { provide: ToastService, useValue: mockToastService }, { provide: DialogRef, useValue: mockDialogRef }, @@ -211,7 +211,7 @@ describe("ChangeKdfConfirmationComponent", () => { message: "encKeySettingsChanged-used-i18n", }); expect(mockDialogRef.close).toHaveBeenCalled(); - expect(mockMessagingService.send).not.toHaveBeenCalled(); + expect(mockLogoutService.logout).not.toHaveBeenCalled(); }); it("sends a logout and displays a log back in toast when feature flag is disabled", async () => { @@ -235,7 +235,7 @@ describe("ChangeKdfConfirmationComponent", () => { title: "encKeySettingsChanged-used-i18n", message: "logBackIn-used-i18n", }); - expect(mockMessagingService.send).toHaveBeenCalledWith("logout"); + expect(mockLogoutService.logout).toHaveBeenCalledWith(mockUserId, "kdfSettingsChanged"); expect(mockDialogRef.close).not.toHaveBeenCalled(); }); }); diff --git a/apps/web/src/app/key-management/change-kdf/change-kdf-confirmation.component.ts b/apps/web/src/app/key-management/change-kdf/change-kdf-confirmation.component.ts index ffeabffa019..85642126769 100644 --- a/apps/web/src/app/key-management/change-kdf/change-kdf-confirmation.component.ts +++ b/apps/web/src/app/key-management/change-kdf/change-kdf-confirmation.component.ts @@ -2,13 +2,13 @@ import { Component, Inject } from "@angular/core"; import { FormGroup, FormControl, Validators } from "@angular/forms"; import { firstValueFrom, Observable } from "rxjs"; +import { LogoutService } from "@bitwarden/auth/common"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; import { ChangeKdfService } from "@bitwarden/common/key-management/kdf/change-kdf.service.abstraction"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { DIALOG_DATA, DialogRef, ToastService } from "@bitwarden/components"; import { KdfConfig, KdfType } from "@bitwarden/key-management"; @@ -32,13 +32,13 @@ export class ChangeKdfConfirmationComponent { constructor( private i18nService: I18nService, - private messagingService: MessagingService, @Inject(DIALOG_DATA) params: { kdf: KdfType; kdfConfig: KdfConfig }, private accountService: AccountService, private toastService: ToastService, private changeKdfService: ChangeKdfService, private dialogRef: DialogRef, configService: ConfigService, + private logoutService: LogoutService, ) { this.kdfConfig = params.kdfConfig; this.noLogoutOnKdfChangeFeatureFlag$ = configService.getFeatureFlag$( @@ -51,6 +51,7 @@ export class ChangeKdfConfirmationComponent { return; } this.loading = true; + const activeAccountId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); await this.makeKeyAndSave(); if (await firstValueFrom(this.noLogoutOnKdfChangeFeatureFlag$)) { this.toastService.showToast({ @@ -64,7 +65,9 @@ export class ChangeKdfConfirmationComponent { title: this.i18nService.t("encKeySettingsChanged"), message: this.i18nService.t("logBackIn"), }); - this.messagingService.send("logout"); + if (activeAccountId) { + await this.logoutService.logout(activeAccountId, "kdfSettingsChanged"); + } } this.loading = false; }; diff --git a/apps/web/src/app/layouts/header/web-header.component.ts b/apps/web/src/app/layouts/header/web-header.component.ts index 694ee5c4ae9..4976710a071 100644 --- a/apps/web/src/app/layouts/header/web-header.component.ts +++ b/apps/web/src/app/layouts/header/web-header.component.ts @@ -2,9 +2,10 @@ // @ts-strict-ignore import { Component, Input } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; -import { map, Observable } from "rxjs"; +import { firstValueFrom, map, Observable } from "rxjs"; import { User } from "@bitwarden/angular/pipes/user-name.pipe"; +import { LogoutService } from "@bitwarden/auth/common"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { VaultTimeoutAction, @@ -48,6 +49,7 @@ export class WebHeaderComponent { private vaultTimeoutSettingsService: VaultTimeoutSettingsService, private messagingService: MessagingService, private accountService: AccountService, + private logoutService: LogoutService, ) { this.routeData$ = this.route.data.pipe( map((params) => { @@ -69,7 +71,10 @@ export class WebHeaderComponent { this.messagingService.send("lockVault"); } - protected logout() { - this.messagingService.send("logout"); + protected async logout() { + const account = await firstValueFrom(this.account$); + if (account?.id) { + await this.logoutService.logout(account.id, "userInitiated"); + } } } diff --git a/libs/angular/src/auth/password-management/set-initial-password/set-initial-password.component.ts b/libs/angular/src/auth/password-management/set-initial-password/set-initial-password.component.ts index 365ec97801c..799207c828f 100644 --- a/libs/angular/src/auth/password-management/set-initial-password/set-initial-password.component.ts +++ b/libs/angular/src/auth/password-management/set-initial-password/set-initial-password.component.ts @@ -25,7 +25,6 @@ import { assertTruthy, assertNonNullish } from "@bitwarden/common/auth/utils"; import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { SyncService } from "@bitwarden/common/platform/sync"; import { UserId } from "@bitwarden/common/types/guid"; @@ -76,7 +75,6 @@ export class SetInitialPasswordComponent implements OnInit { private logoutService: LogoutService, private logService: LogService, private masterPasswordService: InternalMasterPasswordServiceAbstraction, - private messagingService: MessagingService, private organizationApiService: OrganizationApiServiceAbstraction, private policyApiService: PolicyApiServiceAbstraction, private policyService: PolicyService, @@ -317,7 +315,7 @@ export class SetInitialPasswordComponent implements OnInit { }); if (confirmed) { - this.messagingService.send("logout"); + await this.logoutService.logout(this.userId, "userInitiated"); } } } diff --git a/libs/auth/src/angular/login-decryption-options/default-login-decryption-options.service.spec.ts b/libs/auth/src/angular/login-decryption-options/default-login-decryption-options.service.spec.ts index 735b7667540..3330f00d4bd 100644 --- a/libs/auth/src/angular/login-decryption-options/default-login-decryption-options.service.spec.ts +++ b/libs/auth/src/angular/login-decryption-options/default-login-decryption-options.service.spec.ts @@ -1,18 +1,10 @@ -import { MockProxy, mock } from "jest-mock-extended"; - -import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; - import { DefaultLoginDecryptionOptionsService } from "./default-login-decryption-options.service"; describe("DefaultLoginDecryptionOptionsService", () => { let service: DefaultLoginDecryptionOptionsService; - let messagingService: MockProxy; - beforeEach(() => { - messagingService = mock(); - - service = new DefaultLoginDecryptionOptionsService(messagingService); + service = new DefaultLoginDecryptionOptionsService(); }); it("should instantiate the service", () => { @@ -26,12 +18,4 @@ describe("DefaultLoginDecryptionOptionsService", () => { expect(result).toBeNull(); }); }); - - describe("logOut()", () => { - it("should send a logout message", async () => { - await service.logOut(); - - expect(messagingService.send).toHaveBeenCalledWith("logout"); - }); - }); }); diff --git a/libs/auth/src/angular/login-decryption-options/default-login-decryption-options.service.ts b/libs/auth/src/angular/login-decryption-options/default-login-decryption-options.service.ts index c5d593d4d85..ba6acf25eda 100644 --- a/libs/auth/src/angular/login-decryption-options/default-login-decryption-options.service.ts +++ b/libs/auth/src/angular/login-decryption-options/default-login-decryption-options.service.ts @@ -1,17 +1,11 @@ // FIXME: Update this file to be type safe and remove this and next line // @ts-strict-ignore -import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; - import { LoginDecryptionOptionsService } from "./login-decryption-options.service"; export class DefaultLoginDecryptionOptionsService implements LoginDecryptionOptionsService { - constructor(protected messagingService: MessagingService) {} + constructor() {} handleCreateUserSuccess(): Promise { return null; } - - async logOut(): Promise { - this.messagingService.send("logout"); - } } diff --git a/libs/auth/src/common/types/logout-reason.type.ts b/libs/auth/src/common/types/logout-reason.type.ts index fd9da00bcf7..6a947726db5 100644 --- a/libs/auth/src/common/types/logout-reason.type.ts +++ b/libs/auth/src/common/types/logout-reason.type.ts @@ -1,15 +1,19 @@ export type LogoutReason = | "accessTokenUnableToBeDecrypted" | "accountDeleted" + | "emailChanged" | "invalidAccessToken" | "invalidSecurityStamp" + | "kdfSettingsChanged" | "keyConnectorError" | "logoutNotification" | "missingEmailError" | "noUnlockOptionsAvailable" | "refreshTokenSecureStorageRetrievalFailure" + | "sessionsDeauthorized" | "sessionExpired" | "setInitialPassword" + | "tooManyInvalidPinAttempts" | "userInitiated" | "userKeyRotation" | "vaultTimeout"; diff --git a/libs/key-management-ui/src/key-connector/confirm-key-connector-domain.component.spec.ts b/libs/key-management-ui/src/key-connector/confirm-key-connector-domain.component.spec.ts index ad0b783eee3..bc6272c27d6 100644 --- a/libs/key-management-ui/src/key-connector/confirm-key-connector-domain.component.spec.ts +++ b/libs/key-management-ui/src/key-connector/confirm-key-connector-domain.component.spec.ts @@ -2,6 +2,7 @@ import { Router } from "@angular/router"; import { mock } from "jest-mock-extended"; import { of } from "rxjs"; +import { LogoutService } from "@bitwarden/auth/common"; import { KeyConnectorApiService } from "@bitwarden/common/key-management/key-connector/abstractions/key-connector-api.service"; import { KeyConnectorService } from "@bitwarden/common/key-management/key-connector/abstractions/key-connector.service"; import { KeyConnectorDomainConfirmation } from "@bitwarden/common/key-management/key-connector/models/key-connector-domain-confirmation"; @@ -35,6 +36,7 @@ describe("ConfirmKeyConnectorDomainComponent", () => { const mockToastService = mock(); const mockI18nService = mock(); const mockAnonLayoutWrapperDataService = mock(); + const mockLogoutService = mock(); let mockAccountService = mockAccountServiceWith(userId); const onBeforeNavigation = jest.fn(); @@ -56,6 +58,7 @@ describe("ConfirmKeyConnectorDomainComponent", () => { mockToastService, mockI18nService, mockAnonLayoutWrapperDataService, + mockLogoutService, ); jest.spyOn(component, "onBeforeNavigation").mockImplementation(onBeforeNavigation); @@ -79,7 +82,7 @@ describe("ConfirmKeyConnectorDomainComponent", () => { await component.ngOnInit(); - expect(mockMessagingService.send).toHaveBeenCalledWith("logout"); + expect(mockLogoutService.logout).toHaveBeenCalledWith(userId, "keyConnectorError"); expect(component.loading).toEqual(true); }); @@ -186,7 +189,7 @@ describe("ConfirmKeyConnectorDomainComponent", () => { await component.cancel(); - expect(mockMessagingService.send).toHaveBeenCalledWith("logout"); + expect(mockLogoutService.logout).toHaveBeenCalledWith(userId, "userInitiated"); expect(mockKeyConnectorService.convertNewSsoUserToKeyConnector).not.toHaveBeenCalled(); }); }); diff --git a/libs/key-management-ui/src/key-connector/confirm-key-connector-domain.component.ts b/libs/key-management-ui/src/key-connector/confirm-key-connector-domain.component.ts index aa65f4c43f9..a76cd754836 100644 --- a/libs/key-management-ui/src/key-connector/confirm-key-connector-domain.component.ts +++ b/libs/key-management-ui/src/key-connector/confirm-key-connector-domain.component.ts @@ -3,6 +3,7 @@ import { Component, Input, OnInit } from "@angular/core"; import { Router } from "@angular/router"; import { firstValueFrom } from "rxjs"; +import { LogoutService } from "@bitwarden/auth/common"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { KeyConnectorApiService } from "@bitwarden/common/key-management/key-connector/abstractions/key-connector-api.service"; @@ -52,6 +53,7 @@ export class ConfirmKeyConnectorDomainComponent implements OnInit { private toastService: ToastService, private i18nService: I18nService, private anonLayoutWrapperDataService: AnonLayoutWrapperDataService, + private logoutService: LogoutService, ) {} async ngOnInit() { @@ -59,6 +61,7 @@ export class ConfirmKeyConnectorDomainComponent implements OnInit { this.userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); } catch { this.logService.info("[confirm-key-connector-domain] no active account"); + // No userId available, use messaging service directly this.messagingService.send("logout"); return; } @@ -68,7 +71,7 @@ export class ConfirmKeyConnectorDomainComponent implements OnInit { ); if (confirmation == null) { this.logService.info("[confirm-key-connector-domain] missing required parameters"); - this.messagingService.send("logout"); + await this.logoutService.logout(this.userId, "keyConnectorError"); return; } @@ -112,7 +115,7 @@ export class ConfirmKeyConnectorDomainComponent implements OnInit { }; cancel = async () => { - this.messagingService.send("logout"); + await this.logoutService.logout(this.userId, "userInitiated"); }; private async getOrganizationName( diff --git a/libs/key-management-ui/src/lock/components/lock.component.ts b/libs/key-management-ui/src/lock/components/lock.component.ts index fe4dcd4bbf5..76638dd7b57 100644 --- a/libs/key-management-ui/src/lock/components/lock.component.ts +++ b/libs/key-management-ui/src/lock/components/lock.component.ts @@ -499,7 +499,9 @@ export class LockComponent implements OnInit, OnDestroy { variant: "error", message: this.i18nService.t("tooManyInvalidPinEntryAttemptsLoggingOut"), }); - this.messagingService.send("logout"); + if (this.activeAccount?.id != null) { + await this.logoutService.logout(this.activeAccount.id, "tooManyInvalidPinAttempts"); + } return; }