Enter below a 6-digit one-time code generated by your authentication app.
+ {:else if challengeType == AuthenticationFactor.Email}
+
A 6-digit verification code was sent to your email, enter it below.
+ {:else if challengeType == AuthenticationFactor.Phone}
+
A 6-digit verification code was sent to your phone, enter it below.
+ {/if}
+
+ {:else}
+
+
+
+
+
Insert your security key into your device and press authenticate.
+
+
{/if}
-
{/if}
{#if showVerifyButton}
diff --git a/src/lib/sdk/account.ts b/src/lib/sdk/account.ts
index 4ec1b22a9..8da8a1493 100644
--- a/src/lib/sdk/account.ts
+++ b/src/lib/sdk/account.ts
@@ -1,5 +1,5 @@
import type { Client, Models } from '@appwrite.io/console';
-import { startRegistration } from '@simplewebauthn/browser';
+import { startRegistration, startAuthentication } from '@simplewebauthn/browser';
export type WebauthnRegisterChallenge = {
$id: string;
@@ -61,8 +61,45 @@ export class Account {
//TODO Replace with native navigator.credentials.create
let credential = await startRegistration(challenge);
- let session = await this.completeWebauthnMfaAuthenticator(credential);
- console.log(session);
+ await this.completeWebauthnMfaAuthenticator(credential);
}
+ async createMfaWebauthnChallenge() {
+ const path = '/account/mfa/challenge/webauthn';
+
+ const uri = new URL(this.client.config.endpoint + path);
+ return await this.client.call(
+ 'POST',
+ uri,
+ {
+ 'content-type': 'application/json'
+ },
+ );
+ }
+
+ async completeMfaWebauthnChallenge(challengeId: string, credential: Credential) {
+ const path = '/account/mfa/challenge/webauthn';
+
+ const uri = new URL(this.client.config.endpoint + path);
+ return await this.client.call(
+ 'PUT',
+ uri,
+ {
+ 'content-type': 'application/json'
+ },
+ {
+ challengeId: challengeId,
+ challengeResponse: JSON.stringify(credential)
+ }
+ );
+ }
+
+ async createMfaWebauthnChallengeHelper() {
+ let challenge = await this.createMfaWebauthnChallenge();
+
+ //TODO Replace with native navigator.credentials.create
+ let credential = await startAuthentication(challenge);
+
+ await this.completeMfaWebauthnChallenge(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
new file mode 100644
index 000000000..05a96219d
--- /dev/null
+++ b/src/routes/console/account/deleteWebauthn.svelte
@@ -0,0 +1,58 @@
+
+
+
+
Please authenticate with your Webauthn Device to continue.
+
+
+
+
+
+
+
+
+
diff --git a/src/routes/console/account/updateMfa.svelte b/src/routes/console/account/updateMfa.svelte
index e95c29b67..2353b987c 100644
--- a/src/routes/console/account/updateMfa.svelte
+++ b/src/routes/console/account/updateMfa.svelte
@@ -15,6 +15,7 @@
import MfaRegenerateCodes from './mfaRegenerateCodes.svelte';
import { Pill } from '$lib/elements';
import WebauthnMfa from './webauthnMfa.svelte';
+ import DeleteWebauthn from './deleteWebauthn.svelte';
let showSetup: boolean = false;
let showDelete: boolean = false;
@@ -147,13 +148,18 @@
- Security Key
+ Webauthn
+ {#if $factors.webauthn}
+ A webauthn key has been added to this account.
+ {:else}
Use a security key to provide two-factor for your account.
+ {/if}