From 545d9c7993c46b7e65d919d099d55a18bd0ea278 Mon Sep 17 00:00:00 2001 From: balzack Date: Wed, 11 Sep 2024 18:35:56 -0700 Subject: [PATCH] fixing mfauth --- app/client/web/src/settings/Settings.tsx | 19 ++++++++++++++----- .../web/src/settings/useSettings.hook.ts | 4 ++-- app/sdk/src/entities.ts | 4 ++-- app/sdk/src/net/removeAccountMFAuth.ts | 2 +- app/sdk/src/net/setAccountMFAuth.ts | 2 +- app/sdk/src/settings.ts | 4 ++-- app/sdk/src/types.ts | 2 +- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/client/web/src/settings/Settings.tsx b/app/client/web/src/settings/Settings.tsx index 2184d3ed..0e18b614 100644 --- a/app/client/web/src/settings/Settings.tsx +++ b/app/client/web/src/settings/Settings.tsx @@ -130,8 +130,12 @@ export function Settings({ showLogout }: { showLogout: boolean }) { if (!addingMfa) { setAddingMfa(true); try { - await actions.enableMFA(); - mfaOpen(); + if (checked) { + await actions.enableMFA(); + mfaOpen(); + } else { + await actions.disableMFA(); + } } catch (err) { console.log(err) showError() @@ -143,9 +147,13 @@ export function Settings({ showLogout }: { showLogout: boolean }) { const confirmMfa = async () => { if (!savingMfa) { setSavingMfa(true); - - mfaClose(); - + try { + await actions.confirmMFA(); + mfaClose(); + } catch (err) { + console.log(err); + showError(); + } setSavingMfa(false); } } @@ -351,6 +359,7 @@ export function Settings({ showLogout }: { showLogout: boolean }) { {state.strings.mfaTitle} setMfa(ev.currentTarget.checked)} /> diff --git a/app/client/web/src/settings/useSettings.hook.ts b/app/client/web/src/settings/useSettings.hook.ts index 17d9cc11..dd1df0ed 100644 --- a/app/client/web/src/settings/useSettings.hook.ts +++ b/app/client/web/src/settings/useSettings.hook.ts @@ -159,9 +159,9 @@ export function useSettings() { const { settings } = getSession() await settings.disableMFA() }, - confirmMFA: async (code: string) => { + confirmMFA: async () => { const { settings } = getSession() - await settings.confirmMFA(code) + await settings.confirmMFA(state.code) }, setCode: (code: string) => { updateState({ code }); diff --git a/app/sdk/src/entities.ts b/app/sdk/src/entities.ts index ee167c21..9cd5d42a 100644 --- a/app/sdk/src/entities.ts +++ b/app/sdk/src/entities.ts @@ -160,7 +160,7 @@ export type ConfigEntity = { sealable: boolean, seal: SealEntity, enableIce: boolean, - multiFactorAuth: boolean, + mfaEnabled: boolean, webPushKey: string, } @@ -175,7 +175,7 @@ export const defaultConfigEntity = { seal: { passwordSalt: '', privateKeyIv: '', privateKeyEncrypted: '', publicKey: '' }, sealable: false, enableIce: false, - multiFactorAuth: false, + mfaEnabled: false, webPushKey: '', }; diff --git a/app/sdk/src/net/removeAccountMFAuth.ts b/app/sdk/src/net/removeAccountMFAuth.ts index 265aae87..6548de7b 100644 --- a/app/sdk/src/net/removeAccountMFAuth.ts +++ b/app/sdk/src/net/removeAccountMFAuth.ts @@ -1,7 +1,7 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function removeAccountMFAuth(node: string, secure: boolean, token: string) { - const endpoint = `http${secure ? 's' : ''}://${node}/account/mfauth=${token}`; + const endpoint = `http${secure ? 's' : ''}://${node}/account/mfauth?agent=${token}`; const { status } = await fetchWithTimeout(endpoint, { method: 'DELETE' }) checkResponse(status); } diff --git a/app/sdk/src/net/setAccountMFAuth.ts b/app/sdk/src/net/setAccountMFAuth.ts index 9c0cb4f3..8605c604 100644 --- a/app/sdk/src/net/setAccountMFAuth.ts +++ b/app/sdk/src/net/setAccountMFAuth.ts @@ -1,7 +1,7 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function setAccountMFAuth(node: string, secure: boolean, token: string, code: string) { - const endpoint = `http${secure ? 's' : ''}://${node}/account/agent=${token}&code=${code}`; + const endpoint = `http${secure ? 's' : ''}://${node}/account/mfauth?agent=${token}&code=${code}`; const { status } = await fetchWithTimeout(endpoint, { method: 'PUT' }) checkResponse(status); } diff --git a/app/sdk/src/settings.ts b/app/sdk/src/settings.ts index 9321b9a0..209fee6e 100644 --- a/app/sdk/src/settings.ts +++ b/app/sdk/src/settings.ts @@ -95,11 +95,11 @@ export class SettingsModule implements Settings { } public getConfig() { - const { storageUsed, storageAvailable, forwardingAddress, searchable, allowUnsealed, pushEnabled, sealable, seal, enableIce, multiFactorAuth, webPushKey } = this.config; + const { storageUsed, storageAvailable, forwardingAddress, searchable, allowUnsealed, pushEnabled, sealable, seal, enableIce, mfaEnabled, webPushKey } = this.config; const { passwordSalt, privateKeyIv, privateKeyEncrypted, publicKey } = seal || {}; const sealSet = Boolean(passwordSalt && privateKeyIv && privateKeyEncrypted && publicKey); const sealUnlocked = Boolean(sealSet && this.sealKey?.privateKey && this.sealKey?.publicKey == publicKey) - return { storageUsed, storageAvailable, forwardingAddress, searchable, allowUnsealed, pushEnabled, sealable, sealSet, sealUnlocked, enableIce, multiFactorAuth, webPushKey }; + return { storageUsed, storageAvailable, forwardingAddress, searchable, allowUnsealed, pushEnabled, sealable, sealSet, sealUnlocked, enableIce, mfaEnabled, webPushKey }; } public addConfigListener(ev: (config: Config) => void): void { diff --git a/app/sdk/src/types.ts b/app/sdk/src/types.ts index 11eaaef6..1232f1a1 100644 --- a/app/sdk/src/types.ts +++ b/app/sdk/src/types.ts @@ -155,7 +155,7 @@ export type Config = { sealSet: boolean, sealUnlocked: boolean, enableIce: boolean, - multiFactorAuth: boolean, + mfaEnabled: boolean, webPushKey: string, }