From 02a04de1d5d4f1562052ad97f72cd9d982da7e0d Mon Sep 17 00:00:00 2001 From: rr-bw <102181210+rr-bw@users.noreply.github.com> Date: Fri, 17 Oct 2025 10:07:09 -0700 Subject: [PATCH] update abstraction --- apps/browser/src/background/main.background.ts | 3 ++- .../auth-request-answering.service.abstraction.ts | 9 +++++++++ .../default-auth-request-answering.service.ts | 5 +++++ .../noop-auth-request-answering.service.ts | 5 ++++- .../internal/default-server-notifications.service.ts | 6 +++--- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index ba785b23a66..d382e9367a9 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -39,6 +39,7 @@ import { DefaultPolicyService } from "@bitwarden/common/admin-console/services/p import { PolicyApiService } from "@bitwarden/common/admin-console/services/policy/policy-api.service"; import { ProviderService } from "@bitwarden/common/admin-console/services/provider.service"; import { AccountService as AccountServiceAbstraction } from "@bitwarden/common/auth/abstractions/account.service"; +import { AuthRequestAnsweringService } from "@bitwarden/common/auth/abstractions/auth-request-answering/auth-request-answering.service.abstraction"; import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth.service"; import { AvatarService as AvatarServiceAbstraction } from "@bitwarden/common/auth/abstractions/avatar.service"; import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction"; @@ -374,7 +375,7 @@ export default class MainBackground { serverNotificationsService: ServerNotificationsService; systemNotificationService: SystemNotificationsService; actionsService: ActionsService; - authRequestAnsweringService: ExtensionAuthRequestAnsweringService; + authRequestAnsweringService: AuthRequestAnsweringService; stateService: StateServiceAbstraction; userNotificationSettingsService: UserNotificationSettingsServiceAbstraction; autofillSettingsService: AutofillSettingsServiceAbstraction; diff --git a/libs/common/src/auth/abstractions/auth-request-answering/auth-request-answering.service.abstraction.ts b/libs/common/src/auth/abstractions/auth-request-answering/auth-request-answering.service.abstraction.ts index 4f6ff8c17a8..ec4bfdd698c 100644 --- a/libs/common/src/auth/abstractions/auth-request-answering/auth-request-answering.service.abstraction.ts +++ b/libs/common/src/auth/abstractions/auth-request-answering/auth-request-answering.service.abstraction.ts @@ -1,3 +1,4 @@ +import { SystemNotificationEvent } from "@bitwarden/common/platform/system-notifications/system-notifications.service"; import { UserId } from "@bitwarden/user-core"; export abstract class AuthRequestAnsweringService { @@ -27,6 +28,14 @@ export abstract class AuthRequestAnsweringService { */ abstract userMeetsConditionsToShowApprovalDialog(userId: UserId): Promise; + /** + * When a system notification is clicked, this function is used to process that event. + * - Implemented in Extension only + * + * @param event The event passed in. Check initNotificationSubscriptions in main.background.ts. + */ + abstract handleAuthRequestNotificationClicked(event: SystemNotificationEvent): Promise; + /** * Process notifications that have been received but didn't meet the conditions to display the * approval dialog. diff --git a/libs/common/src/auth/services/auth-request-answering/default-auth-request-answering.service.ts b/libs/common/src/auth/services/auth-request-answering/default-auth-request-answering.service.ts index f98156b6b67..026efe6dae4 100644 --- a/libs/common/src/auth/services/auth-request-answering/default-auth-request-answering.service.ts +++ b/libs/common/src/auth/services/auth-request-answering/default-auth-request-answering.service.ts @@ -7,6 +7,7 @@ import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/for import { getOptionalUserId, getUserId } from "@bitwarden/common/auth/services/account.service"; import { MasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; +import { SystemNotificationEvent } from "@bitwarden/common/platform/system-notifications/system-notifications.service"; import { UserId } from "@bitwarden/user-core"; import { AuthRequestAnsweringService } from "../../abstractions/auth-request-answering/auth-request-answering.service.abstraction"; @@ -53,6 +54,10 @@ export class DefaultAuthRequestAnsweringService implements AuthRequestAnsweringS return meetsConditions; } + async handleAuthRequestNotificationClicked(event: SystemNotificationEvent) { + throw new Error("handleAuthRequestNotificationClicked() not implemented for this client"); + } + async processPendingAuthRequests(): Promise { // Prune any stale pending requests (older than 15 minutes) // This comes from GlobalSettings.cs diff --git a/libs/common/src/auth/services/auth-request-answering/noop-auth-request-answering.service.ts b/libs/common/src/auth/services/auth-request-answering/noop-auth-request-answering.service.ts index 295ff0270ec..e6f062f85a0 100644 --- a/libs/common/src/auth/services/auth-request-answering/noop-auth-request-answering.service.ts +++ b/libs/common/src/auth/services/auth-request-answering/noop-auth-request-answering.service.ts @@ -1,3 +1,4 @@ +import { SystemNotificationEvent } from "@bitwarden/common/platform/system-notifications/system-notifications.service"; import { UserId } from "@bitwarden/user-core"; import { AuthRequestAnsweringService } from "../../abstractions/auth-request-answering/auth-request-answering.service.abstraction"; @@ -8,8 +9,10 @@ export class NoopAuthRequestAnsweringService implements AuthRequestAnsweringServ async receivedPendingAuthRequest(userId: UserId, notificationId: string): Promise {} async userMeetsConditionsToShowApprovalDialog(userId: UserId): Promise { - return false; + throw new Error("userMeetsConditionsToShowApprovalDialog() not implemented for this client"); } + async handleAuthRequestNotificationClicked(event: SystemNotificationEvent) {} + async processPendingAuthRequests(): Promise {} } diff --git a/libs/common/src/platform/server-notifications/internal/default-server-notifications.service.ts b/libs/common/src/platform/server-notifications/internal/default-server-notifications.service.ts index 7d4d56ff316..9f9b72622f2 100644 --- a/libs/common/src/platform/server-notifications/internal/default-server-notifications.service.ts +++ b/libs/common/src/platform/server-notifications/internal/default-server-notifications.service.ts @@ -293,9 +293,9 @@ export class DefaultServerNotificationsService implements ServerNotificationsSer * pending auth request to process at a time, so this second call will not cause any * duplicate processing conflicts on Extension. */ - // this.messagingService.send("openLoginApproval", { - // notificationId: notification.payload.id, - // }); + this.messagingService.send("openLoginApproval", { + notificationId: notification.payload.id, + }); break; case NotificationType.SyncOrganizationStatusChanged: await this.syncService.fullSync(true);