1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-28 10:33:31 +00:00

fix(browser-approval): [PM-23620] Auth Request Answering Service - Work in progress.

This commit is contained in:
Patrick Pimentel
2025-07-24 11:26:51 -04:00
parent 49e7f15eda
commit 924adb500d
13 changed files with 174 additions and 25 deletions

View File

@@ -0,0 +1,8 @@
import { SystemNotificationEvent } from "@bitwarden/common/platform/notifications/system-notifications-service";
import { UserId } from "@bitwarden/user-core";
export abstract class AuthRequestAnsweringServiceAbstraction {
abstract receivedPendingAuthRequest(userId: UserId, notificationId: string): Promise<void>;
abstract handleAuthRequestNotificationClicked(event: SystemNotificationEvent): Promise<void>;
}

View File

@@ -0,0 +1,49 @@
import { filter, mergeMap } from "rxjs";
import { ActionsService } from "@bitwarden/common/platform/actions";
import {
ButtonActions,
ButtonLocation,
SystemNotificationEvent,
SystemNotificationsService,
} from "@bitwarden/common/platform/notifications/system-notifications-service";
import { UserId } from "@bitwarden/user-core";
import { AuthRequestAnsweringServiceAbstraction } from "../../abstractions/auth-request-answering/auth-request-answering.service.abstraction";
export class AuthRequestAnsweringService implements AuthRequestAnsweringServiceAbstraction {
constructor(
private readonly systemNotificationsService: SystemNotificationsService,
private readonly actionService: ActionsService,
) {
this.systemNotificationsService.notificationClicked$
.pipe(
filter(
(event: SystemNotificationEvent) => event.type === ButtonActions.AuthRequestNotification,
),
mergeMap((event: SystemNotificationEvent) =>
this.handleAuthRequestNotificationClicked(event),
),
)
.subscribe();
}
async handleAuthRequestNotificationClicked(event: SystemNotificationEvent): Promise<void> {
if (event.buttonIdentifier === ButtonLocation.NotificationButton) {
// TODO: Uncomment this before going into review
// await this.systemNotificationService.clear({
// id: event.id,
// })
await this.actionService.openPopup();
}
}
async receivedPendingAuthRequest(userId: UserId, notificationId: string): Promise<void> {
await this.systemNotificationsService.create({
id: notificationId,
type: ButtonActions.AuthRequestNotification,
title: "Test (i18n)",
body: "Pending Auth Request to Approve (i18n)",
buttons: [],
});
}
}

View File

@@ -0,0 +1,17 @@
import { SystemNotificationEvent } from "@bitwarden/common/platform/notifications/system-notifications-service";
import { UserId } from "@bitwarden/user-core";
import { AuthRequestAnsweringServiceAbstraction } from "../../abstractions/auth-request-answering/auth-request-answering.service.abstraction";
export class UnsupportedAuthRequestAnsweringService
implements AuthRequestAnsweringServiceAbstraction
{
constructor() {}
async handleAuthRequestNotificationClicked(event: SystemNotificationEvent): Promise<void> {
throw new Error("Received pending auth request not supported.");
}
async receivedPendingAuthRequest(userId: UserId, notificationId: string): Promise<void> {
throw new Error("Received pending auth request not supported.");
}
}