1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

[EC-598] feat: add initial implementation of UI sessions

This commit is contained in:
Andreas Coroiu
2023-04-05 11:38:32 +02:00
parent 55cd736ec3
commit 11d340bc97
5 changed files with 146 additions and 33 deletions

View File

@@ -3,6 +3,7 @@ import { filter, first, lastValueFrom, Observable, Subject, takeUntil } from "rx
import { Utils } from "@bitwarden/common/misc/utils";
import {
Fido2UserInterfaceService as Fido2UserInterfaceServiceAbstraction,
Fido2UserInterfaceSession,
NewCredentialParams,
} from "@bitwarden/common/webauthn/abstractions/fido2-user-interface.service.abstraction";
@@ -87,6 +88,10 @@ export class BrowserFido2UserInterfaceService implements Fido2UserInterfaceServi
constructor(private popupUtilsService: PopupUtilsService) {}
async newSession(abortController?: AbortController): Promise<Fido2UserInterfaceSession> {
return await BrowserFido2UserInterfaceSession.create(this, abortController);
}
async confirmCredential(
cipherId: string,
abortController = new AbortController()
@@ -265,3 +270,71 @@ export class BrowserFido2UserInterfaceService implements Fido2UserInterfaceServi
return setTimeout(() => abortController.abort());
}
}
export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSession {
static async create(
parentService: BrowserFido2UserInterfaceService,
abortController?: AbortController
): Promise<BrowserFido2UserInterfaceSession> {
return new BrowserFido2UserInterfaceSession(parentService, abortController);
}
readonly abortListener: () => void;
private constructor(
private readonly parentService: BrowserFido2UserInterfaceService,
readonly abortController = new AbortController(),
readonly sessionId = Utils.newGuid()
) {
this.abortListener = () => this.abort();
abortController.signal.addEventListener("abort", this.abortListener);
}
fallbackRequested = false;
get aborted() {
return this.abortController.signal.aborted;
}
confirmCredential(cipherId: string, abortController?: AbortController): Promise<boolean> {
return this.parentService.confirmCredential(cipherId, this.abortController);
}
pickCredential(cipherIds: string[], abortController?: AbortController): Promise<string> {
return this.parentService.pickCredential(cipherIds, this.abortController);
}
confirmNewCredential(
params: NewCredentialParams,
abortController?: AbortController
): Promise<boolean> {
return this.parentService.confirmNewCredential(params, this.abortController);
}
confirmNewNonDiscoverableCredential(
params: NewCredentialParams,
abortController?: AbortController
): Promise<string> {
return this.parentService.confirmNewNonDiscoverableCredential(params, this.abortController);
}
informExcludedCredential(
existingCipherIds: string[],
newCredential: NewCredentialParams,
abortController?: AbortController
): Promise<void> {
return this.parentService.informExcludedCredential(
existingCipherIds,
newCredential,
this.abortController
);
}
private abort() {
this.close();
}
private close() {
this.abortController.signal.removeEventListener("abort", this.abortListener);
}
}