mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-30 22:41:33 +01:00
Auth/PM-8113 - Extension - AuthPopoutWindows - Add new method + refactor names (#13020)
* PM-8113 - Add closeSsoAuthResultPopout * PM-8113 - Refactor names / tests / comments
This commit is contained in:
parent
649a196e4b
commit
4abbf32638
@ -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();
|
||||
};
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -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":
|
||||
|
Loading…
Reference in New Issue
Block a user