From 8f98a63e4a0408ad8c2fbc0a9f60655f4857af62 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Wed, 15 Jan 2025 17:09:50 +0100 Subject: [PATCH] Use same uiAuthCallback --- src/CreateCrossSigning.ts | 85 ++++++++++--------- .../encryption/ResetIdentityPanel.tsx | 44 +--------- 2 files changed, 44 insertions(+), 85 deletions(-) diff --git a/src/CreateCrossSigning.ts b/src/CreateCrossSigning.ts index 0c043d9d2bb..d3834bd260a 100644 --- a/src/CreateCrossSigning.ts +++ b/src/CreateCrossSigning.ts @@ -31,49 +31,50 @@ export async function createCrossSigning(cli: MatrixClient): Promise { throw new Error("No crypto API found!"); } - const doBootstrapUIAuth = async ( - makeRequest: (authData: AuthDict) => Promise>, - ): Promise => { - try { - await makeRequest({}); - } catch (error) { - if (!(error instanceof MatrixError) || !error.data || !error.data.flows) { - // Not a UIA response - throw error; - } - - const dialogAesthetics = { - [SSOAuthEntry.PHASE_PREAUTH]: { - title: _t("auth|uia|sso_title"), - body: _t("auth|uia|sso_preauth_body"), - continueText: _t("auth|sso"), - continueKind: "primary", - }, - [SSOAuthEntry.PHASE_POSTAUTH]: { - title: _t("encryption|confirm_encryption_setup_title"), - body: _t("encryption|confirm_encryption_setup_body"), - continueText: _t("action|confirm"), - continueKind: "primary", - }, - }; + await cryptoApi.bootstrapCrossSigning({ + authUploadDeviceSigningKeys: (makeRequest) => uiAuthCallback(cli, makeRequest), + }); +} - const { finished } = Modal.createDialog(InteractiveAuthDialog, { - title: _t("encryption|bootstrap_title"), - matrixClient: cli, - makeRequest, - aestheticsForStagePhases: { - [SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics, - [SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics, - }, - }); - const [confirmed] = await finished; - if (!confirmed) { - throw new Error("Cross-signing key upload auth canceled"); - } +export async function uiAuthCallback( + matrixClient: MatrixClient, + makeRequest: (authData: AuthDict) => Promise>, +): Promise { + try { + await makeRequest({}); + } catch (error) { + if (!(error instanceof MatrixError) || !error.data || !error.data.flows) { + // Not a UIA response + throw error; } - }; - await cryptoApi.bootstrapCrossSigning({ - authUploadDeviceSigningKeys: doBootstrapUIAuth, - }); + const dialogAesthetics = { + [SSOAuthEntry.PHASE_PREAUTH]: { + title: _t("auth|uia|sso_title"), + body: _t("auth|uia|sso_preauth_body"), + continueText: _t("auth|sso"), + continueKind: "primary", + }, + [SSOAuthEntry.PHASE_POSTAUTH]: { + title: _t("encryption|confirm_encryption_setup_title"), + body: _t("encryption|confirm_encryption_setup_body"), + continueText: _t("action|confirm"), + continueKind: "primary", + }, + }; + + const { finished } = Modal.createDialog(InteractiveAuthDialog, { + title: _t("encryption|bootstrap_title"), + matrixClient, + makeRequest, + aestheticsForStagePhases: { + [SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics, + [SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics, + }, + }); + const [confirmed] = await finished; + if (!confirmed) { + throw new Error("Cross-signing key upload auth canceled"); + } + } } diff --git a/src/components/views/settings/encryption/ResetIdentityPanel.tsx b/src/components/views/settings/encryption/ResetIdentityPanel.tsx index 33f5cf1a4a9..c9113e9fe70 100644 --- a/src/components/views/settings/encryption/ResetIdentityPanel.tsx +++ b/src/components/views/settings/encryption/ResetIdentityPanel.tsx @@ -10,14 +10,11 @@ import CheckIcon from "@vector-im/compound-design-tokens/assets/web/icons/check" import InfoIcon from "@vector-im/compound-design-tokens/assets/web/icons/info"; import ErrorIcon from "@vector-im/compound-design-tokens/assets/web/icons/error"; import React, { MouseEventHandler } from "react"; -import { AuthDict, MatrixClient, UIAResponse } from "matrix-js-sdk/src/matrix"; import { _t } from "../../../../languageHandler"; import { EncryptionCard } from "./EncryptionCard"; -import Modal from "../../../../Modal"; -import InteractiveAuthDialog from "../../dialogs/InteractiveAuthDialog"; import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext"; -import { SSOAuthEntry } from "../../auth/InteractiveAuthEntryComponents"; +import { uiAuthCallback } from "../../../../CreateCrossSigning"; interface ResetIdentityPanelProps { /** @@ -84,42 +81,3 @@ export function ResetIdentityPanel({ onCancelClick, onFinish }: ResetIdentityPan ); } - -/** - * Handles the UIA flow for resetting the identity. - * @param matrixClient - * @param makeRequest - */ -async function uiAuthCallback( - matrixClient: MatrixClient, - makeRequest: (authData: AuthDict) => Promise>, -): Promise { - const dialogAesthetics = { - [SSOAuthEntry.PHASE_PREAUTH]: { - title: _t("auth|uia|sso_title"), - body: _t("auth|uia|sso_preauth_body"), - continueText: _t("auth|sso"), - continueKind: "primary", - }, - [SSOAuthEntry.PHASE_POSTAUTH]: { - title: _t("encryption|confirm_encryption_setup_title"), - body: _t("encryption|confirm_encryption_setup_body"), - continueText: _t("action|confirm"), - continueKind: "primary", - }, - }; - - const { finished } = Modal.createDialog(InteractiveAuthDialog, { - title: _t("encryption|bootstrap_title"), - matrixClient, - makeRequest, - aestheticsForStagePhases: { - [SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics, - [SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics, - }, - }); - const [confirmed] = await finished; - if (!confirmed) { - throw new Error("Cross-signing key upload auth canceled"); - } -}