diff --git a/apps/browser/src/auth/popup/two-factor.component.ts b/apps/browser/src/auth/popup/two-factor.component.ts index a2f9cd9d0f..43230bd23f 100644 --- a/apps/browser/src/auth/popup/two-factor.component.ts +++ b/apps/browser/src/auth/popup/two-factor.component.ts @@ -33,7 +33,7 @@ import { BrowserApi } from "../../platform/browser/browser-api"; import { ZonedMessageListenerService } from "../../platform/browser/zoned-message-listener.service"; import BrowserPopupUtils from "../../platform/popup/browser-popup-utils"; -import { closeTwoFactorAuthPopout } from "./utils/auth-popout-window"; +import { closeTwoFactorAuthWebAuthnPopout } from "./utils/auth-popout-window"; @Component({ selector: "app-two-factor", @@ -171,7 +171,7 @@ export class TwoFactorComponent extends BaseTwoFactorComponent implements OnInit // We don't need this window anymore because the intent is for the user to be left // on the web vault screen which tells them to continue in the browser extension (sidebar or popup) - await closeTwoFactorAuthPopout(); + await closeTwoFactorAuthWebAuthnPopout(); }; } }); diff --git a/apps/browser/src/auth/popup/utils/auth-popout-window.spec.ts b/apps/browser/src/auth/popup/utils/auth-popout-window.spec.ts index 9e7d69fad9..deb71f73cd 100644 --- a/apps/browser/src/auth/popup/utils/auth-popout-window.spec.ts +++ b/apps/browser/src/auth/popup/utils/auth-popout-window.spec.ts @@ -7,8 +7,9 @@ import { openUnlockPopout, closeUnlockPopout, openSsoAuthResultPopout, - openTwoFactorAuthPopout, - closeTwoFactorAuthPopout, + openTwoFactorAuthWebAuthnPopout, + closeTwoFactorAuthWebAuthnPopout, + closeSsoAuthResultPopout, } from "./auth-popout-window"; describe("AuthPopoutWindow", () => { @@ -97,22 +98,30 @@ describe("AuthPopoutWindow", () => { }); }); - describe("openTwoFactorAuthPopout", () => { - it("opens a window that facilitates two factor authentication", async () => { - await openTwoFactorAuthPopout({ data: "data", remember: "remember" }); + describe("closeSsoAuthResultPopout", () => { + it("closes the SSO authentication result popout window", async () => { + await closeSsoAuthResultPopout(); + + expect(closeSingleActionPopoutSpy).toHaveBeenCalledWith(AuthPopoutType.ssoAuthResult); + }); + }); + + describe("openTwoFactorAuthWebAuthnPopout", () => { + it("opens a window that facilitates two factor authentication via WebAuthn", async () => { + await openTwoFactorAuthWebAuthnPopout({ data: "data", remember: "remember" }); expect(openPopoutSpy).toHaveBeenCalledWith( "popup/index.html#/2fa;webAuthnResponse=data;remember=remember", - { singleActionKey: AuthPopoutType.twoFactorAuth }, + { singleActionKey: AuthPopoutType.twoFactorAuthWebAuthn }, ); }); }); - describe("closeTwoFactorAuthPopout", () => { - it("closes the two-factor authentication window", async () => { - await closeTwoFactorAuthPopout(); + describe("closeTwoFactorAuthWebAuthnPopout", () => { + it("closes the two-factor authentication WebAuthn window", async () => { + await closeTwoFactorAuthWebAuthnPopout(); - expect(closeSingleActionPopoutSpy).toHaveBeenCalledWith(AuthPopoutType.twoFactorAuth); + expect(closeSingleActionPopoutSpy).toHaveBeenCalledWith(AuthPopoutType.twoFactorAuthWebAuthn); }); }); }); diff --git a/apps/browser/src/auth/popup/utils/auth-popout-window.ts b/apps/browser/src/auth/popup/utils/auth-popout-window.ts index 5a0e577807..8d6e7fa92c 100644 --- a/apps/browser/src/auth/popup/utils/auth-popout-window.ts +++ b/apps/browser/src/auth/popup/utils/auth-popout-window.ts @@ -6,7 +6,7 @@ import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils"; const AuthPopoutType = { unlockExtension: "auth_unlockExtension", ssoAuthResult: "auth_ssoAuthResult", - twoFactorAuth: "auth_twoFactorAuth", + twoFactorAuthWebAuthn: "auth_twoFactorAuthWebAuthn", } as const; const extensionUnlockUrls = new Set([ chrome.runtime.getURL("popup/index.html#/lock"), @@ -60,26 +60,37 @@ async function openSsoAuthResultPopout(resultData: { code: string; state: string } /** - * Opens a window that facilitates two-factor authentication. - * - * @param twoFactorAuthData - The data from the two-factor authentication. + * Closes the SSO authentication result popout window. */ -async function openTwoFactorAuthPopout(twoFactorAuthData: { data: string; remember: string }) { - const { data, remember } = twoFactorAuthData; +async function closeSsoAuthResultPopout() { + await BrowserPopupUtils.closeSingleActionPopout(AuthPopoutType.ssoAuthResult); +} + +/** + * Opens a popout that facilitates two-factor authentication via WebAuthn. + * + * @param twoFactorAuthWebAuthnData - The data to send ot the popout via query param. + * It includes the WebAuthn response and whether to save the 2FA remember me token or not. + */ +async function openTwoFactorAuthWebAuthnPopout(twoFactorAuthWebAuthnData: { + data: string; + remember: string; +}) { + const { data, remember } = twoFactorAuthWebAuthnData; const params = `webAuthnResponse=${encodeURIComponent(data)};` + `remember=${encodeURIComponent(remember)}`; const twoFactorUrl = `popup/index.html#/2fa;${params}`; await BrowserPopupUtils.openPopout(twoFactorUrl, { - singleActionKey: AuthPopoutType.twoFactorAuth, + singleActionKey: AuthPopoutType.twoFactorAuthWebAuthn, }); } /** * Closes the two-factor authentication popout window. */ -async function closeTwoFactorAuthPopout() { - await BrowserPopupUtils.closeSingleActionPopout(AuthPopoutType.twoFactorAuth); +async function closeTwoFactorAuthWebAuthnPopout() { + await BrowserPopupUtils.closeSingleActionPopout(AuthPopoutType.twoFactorAuthWebAuthn); } export { @@ -87,6 +98,7 @@ export { openUnlockPopout, closeUnlockPopout, openSsoAuthResultPopout, - openTwoFactorAuthPopout, - closeTwoFactorAuthPopout, + closeSsoAuthResultPopout, + openTwoFactorAuthWebAuthnPopout, + closeTwoFactorAuthWebAuthnPopout, }; diff --git a/apps/browser/src/background/runtime.background.ts b/apps/browser/src/background/runtime.background.ts index 38bb2ec50c..2f038946bf 100644 --- a/apps/browser/src/background/runtime.background.ts +++ b/apps/browser/src/background/runtime.background.ts @@ -22,7 +22,7 @@ import { BiometricsCommands } from "@bitwarden/key-management"; import { closeUnlockPopout, openSsoAuthResultPopout, - openTwoFactorAuthPopout, + openTwoFactorAuthWebAuthnPopout, } from "../auth/popup/utils/auth-popout-window"; import { LockedVaultPendingNotificationsData } from "../autofill/background/abstractions/notification.background"; import { AutofillService } from "../autofill/services/abstractions/autofill.service"; @@ -333,7 +333,7 @@ export default class RuntimeBackground { return; } - await openTwoFactorAuthPopout(msg); + await openTwoFactorAuthWebAuthnPopout(msg); break; } case "reloadPopup":