diff --git a/apps/desktop/src/app/components/fido2placeholder.component.ts b/apps/desktop/src/app/components/fido2placeholder.component.ts index 1669d82e077..e5d2b9f85bb 100644 --- a/apps/desktop/src/app/components/fido2placeholder.component.ts +++ b/apps/desktop/src/app/components/fido2placeholder.component.ts @@ -1,9 +1,10 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { Router } from "@angular/router"; -import { Fido2UserInterfaceService as Fido2UserInterfaceServiceAbstraction } from "@bitwarden/common/platform/abstractions/fido2/fido2-user-interface.service.abstraction"; - -import { DesktopFido2UserInterfaceService } from "../../autofill/services/desktop-fido2-user-interface.service"; +import { + DesktopFido2UserInterfaceService, + DesktopFido2UserInterfaceSession, +} from "../../autofill/services/desktop-fido2-user-interface.service"; import { DesktopSettingsService } from "../../platform/services/desktop-settings.service"; @Component({ @@ -35,20 +36,22 @@ import { DesktopSettingsService } from "../../platform/services/desktop-settings `, }) -export class Fido2PlaceholderComponent { +export class Fido2PlaceholderComponent implements OnInit { + session?: DesktopFido2UserInterfaceSession = null; constructor( private readonly desktopSettingsService: DesktopSettingsService, - private readonly fido2UserInterfaceService: Fido2UserInterfaceServiceAbstraction, + private readonly fido2UserInterfaceService: DesktopFido2UserInterfaceService, private readonly router: Router, ) {} - async confirmPasskey() { - const desktopUiService = this.fido2UserInterfaceService as DesktopFido2UserInterfaceService; + ngOnInit(): void { + this.session = this.fido2UserInterfaceService.getCurrentSession(); + } + async confirmPasskey() { try { // Retrieve the current UI session to control the flow - const session = desktopUiService.getCurrentSession(); - if (!session) { + if (!this.session) { // todo: handle error throw new Error("No session found"); } @@ -62,7 +65,7 @@ export class Fido2PlaceholderComponent { // userVerification: true, // }); - session.notifyOperationCompleted(); + this.session.notifyConfirmCredential(); // Not sure this clean up should happen here or in session. // The session currently toggles modal on and send us here diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index 37fd9b56187..a1408dab832 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -324,7 +324,7 @@ const safeProviders: SafeProvider[] = [ ], }), safeProvider({ - provide: Fido2UserInterfaceServiceAbstraction, + provide: DesktopFido2UserInterfaceService, useClass: DesktopFido2UserInterfaceService, deps: [ AuthServiceAbstraction, @@ -336,6 +336,10 @@ const safeProviders: SafeProvider[] = [ DesktopSettingsService, ], }), + safeProvider({ + provide: Fido2UserInterfaceServiceAbstraction, // We utilize desktop specific methods when wiring OS API's + useExisting: DesktopFido2UserInterfaceService, + }), safeProvider({ provide: Fido2AuthenticatorServiceAbstraction, useClass: Fido2AuthenticatorService, diff --git a/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts b/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts index d9c8b573664..46171aa130a 100644 --- a/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts +++ b/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts @@ -80,23 +80,23 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi params: PickCredentialParams, ) => Promise<{ cipherId: string; userVerified: boolean }>; - private operationSubject = new Subject(); + private confirmCredentialSubject = new Subject(); private createdCipher: Cipher; /** * Notifies the Fido2UserInterfaceSession that the UI operations has completed and it can return to the OS. */ - notifyOperationCompleted() { - this.operationSubject.next(); - this.operationSubject.complete(); + notifyConfirmCredential() { + this.confirmCredentialSubject.next(); + this.confirmCredentialSubject.complete(); } /** * Returns once the UI has confirmed and completed the operation * @returns */ - private async waitForUICompletion(): Promise { - return lastValueFrom(this.operationSubject); + private async waitForUiCredentialConfirmation(): Promise { + return lastValueFrom(this.confirmCredentialSubject); } /** @@ -119,13 +119,12 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi ); try { - // Load the UI: - // maybe toggling to modal mode shouldn't be done here? - await this.desktopSettingsService.setInModalMode(true); - await this.router.navigate(["/passkeys"]); + await this.showUi(); // Wait for the UI to wrap up - await this.waitForUICompletion(); + await this.waitForUiCredentialConfirmation(); + + // Create the credential await this.createCredential({ credentialName, userName, @@ -148,6 +147,13 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi } } + private async showUi() { + // Load the UI: + // maybe toggling to modal mode shouldn't be done here? + await this.desktopSettingsService.setInModalMode(true); + await this.router.navigate(["/passkeys"]); + } + /** * Can be called by the UI to create a new credential with user input etc. * @param param0