From cd0cddca620b2c657f1f907c6c865e802bd1c4b0 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 5 Jul 2024 14:45:57 +0900 Subject: [PATCH] Add Authenticator Deletion --- src/lib/sdk/account.ts | 26 +++++ .../console/account/deleteWebauthn.svelte | 108 +++++++++++++++++- 2 files changed, 131 insertions(+), 3 deletions(-) diff --git a/src/lib/sdk/account.ts b/src/lib/sdk/account.ts index 8da8a1493..39ae33f37 100644 --- a/src/lib/sdk/account.ts +++ b/src/lib/sdk/account.ts @@ -102,4 +102,30 @@ export class Account { await this.completeMfaWebauthnChallenge(challenge.$id, credential); } + + async deleteMfaWebauthnAuthenticator(challengeId: string, credential: Credential) { + const path = '/account/mfa/authenticator/webauthn'; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'DELETE', + uri, + { + 'content-type': 'application/json' + }, + { + challengeId: challengeId, + challengeResponse: JSON.stringify(credential) + } + ); + } + + + async deleteMfaWebauthnAuthenticatorHelper() { + let challenge = await this.createMfaWebauthnChallenge(); + + let credential = await startAuthentication(challenge); + + await this.deleteMfaWebauthnAuthenticator(challenge.$id, credential); + } } \ No newline at end of file diff --git a/src/routes/console/account/deleteWebauthn.svelte b/src/routes/console/account/deleteWebauthn.svelte index 05a96219d..998fa320c 100644 --- a/src/routes/console/account/deleteWebauthn.svelte +++ b/src/routes/console/account/deleteWebauthn.svelte @@ -8,16 +8,16 @@ import InputDigits from '$lib/elements/forms/inputDigits.svelte'; import { addNotification } from '$lib/stores/notifications'; import { sdk } from '$lib/stores/sdk'; - import { AuthenticatorType } from '@appwrite.io/console'; export let showWebauthnDelete = false; let code: string; let error: string; + let step = 1; async function deleteWebauthnAuthenticator() { try { - await sdk.forConsole.account.deleteMfaAuthenticator(AuthenticatorType.Totp, code); + await sdk.forConsole.webauthnAccount.deleteMfaWebauthnAuthenticatorHelper(); await invalidate(Dependencies.ACCOUNT); await invalidate(Dependencies.FACTORS); showWebauthnDelete = false; @@ -46,13 +46,115 @@ state="warning" bind:error headerDivider={false}> -

Please authenticate with your Webauthn Device to continue.

+ {#if step == 1} +

Please authenticate with your Webauthn Device to finish deletion.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {:else if step == 2} +

Enter your recovery code to finish deletion.

+ {/if} + + {#if step == 1} + + + {:else if step == 2} + + {/if}