mirror of
https://github.com/bitwarden/browser
synced 2026-02-10 21:50:15 +00:00
Cleanup and adress review feedback
This commit is contained in:
@@ -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
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
export class Fido2PlaceholderComponent {
|
||||
export class Fido2PlaceholderComponent implements OnInit {
|
||||
session?: DesktopFido2UserInterfaceSession = null;
|
||||
constructor(
|
||||
private readonly desktopSettingsService: DesktopSettingsService,
|
||||
private readonly fido2UserInterfaceService: Fido2UserInterfaceServiceAbstraction<void>,
|
||||
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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -80,23 +80,23 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi
|
||||
params: PickCredentialParams,
|
||||
) => Promise<{ cipherId: string; userVerified: boolean }>;
|
||||
|
||||
private operationSubject = new Subject<void>();
|
||||
private confirmCredentialSubject = new Subject<void>();
|
||||
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<void> {
|
||||
return lastValueFrom(this.operationSubject);
|
||||
private async waitForUiCredentialConfirmation(): Promise<void> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user