π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Res type
Manav Rathi55fdf2318829
diff --git a/web/apps/accounts/src/pages/passkeys/verify.tsx b/web/apps/accounts/src/pages/passkeys/verify.tsxindex a888ca5069..9d85fae88f 100644--- a/web/apps/accounts/src/pages/passkeys/verify.tsx+++ b/web/apps/accounts/src/pages/passkeys/verify.tsx@@ -1,6 +1,7 @@import { setClientPackageForAuthenticatedRequests } from "@/next/http";import log from "@/next/log";import { clientPackageName } from "@/next/types/app";+import type { TwoFactorAuthorizationResponse } from "@/next/types/credentials";import { nullToUndefined } from "@/utils/transform";import { VerticallyCentered } from "@ente/shared/components/Container";import EnteButton from "@ente/shared/components/EnteButton";@@ -107,9 +108,9 @@ const Page = () => {setStatus("loading");- let authenticationResult;+ let authorizationResponse: TwoFactorAuthorizationResponse;try {- authenticationResult = await finishPasskeyAuthentication(+ authorizationResponse = await finishPasskeyAuthentication(passkeySessionID,ceremonySessionID,credential,@@ -123,7 +124,7 @@ const Page = () => {// Conceptually we can `setStatus("done")` at this point, but we'll// leave this page anyway, so no need to tickle React.- redirectAfterPasskeyAuthentication(redirectURL, authenticationResult);+ redirectAfterPasskeyAuthentication(redirectURL, authorizationResponse);};useEffect(() => {diff --git a/web/apps/accounts/src/services/passkey.ts b/web/apps/accounts/src/services/passkey.tsindex b1fc39b79a..86a9945a66 100644--- a/web/apps/accounts/src/services/passkey.ts+++ b/web/apps/accounts/src/services/passkey.ts@@ -1,5 +1,6 @@import { isDevBuild } from "@/next/env";import { clientPackageHeaderIfPresent } from "@/next/http";+import { TwoFactorAuthorizationResponse } from "@/next/types/credentials";import { ensure } from "@/utils/ensure";import { nullToUndefined } from "@/utils/transform";import {@@ -428,9 +429,8 @@ export const signChallenge = async (* This function implements steps 4 and 5 of the passkey authentication flow.* See [Note: WebAuthn authentication flow].*- * @returns The result of successful authentication. This is an meant to be an- * opaque JavaScript that should be returned back to the calling app by invoking- * {@link redirectAfterPasskeyAuthentication}.+ * @returns The result of successful authentication, a+ * {@link TwoFactorAuthorizationResponse}.*/export const finishPasskeyAuthentication = async (passkeySessionID: string,@@ -473,8 +473,7 @@ export const finishPasskeyAuthentication = async (});if (!res.ok) throw new Error(`Failed to fetch ${url}: HTTP ${res.status}`);- const data = await res.json();- return data.data;+ return TwoFactorAuthorizationResponse.parse(await res.json());};/**@@ -504,21 +503,20 @@ const authenticatorAssertionResponse = (credential: Credential) => {/*** Redirect back to the calling app that initiated the passkey authentication- * flow with the result of the authentication (Ente "credentials" that the- * calling app that calling app can use to continue with the user journey).+ * flow with the result of the authentication.** @param redirectURL The URL to redirect to. Provided by the calling app that* initiated the passkey authentication.*- * @param authenticationResult The result of {@link finishPasskeyAuthentication}- * returned by the backend.+ * @param twoFactorAuthorizationResponse The result of+ * {@link finishPasskeyAuthentication} returned by the backend.*/export const redirectAfterPasskeyAuthentication = (redirectURL: URL,- authenticationResult: any,+ twoFactorAuthorizationResponse: TwoFactorAuthorizationResponse,) => {const encodedResponse = _sodium.to_base64(- JSON.stringify(authenticationResult),+ JSON.stringify(twoFactorAuthorizationResponse),);// TODO-PK: Shouldn't this be URL encoded?diff --git a/web/packages/next/types/credentials.ts b/web/packages/next/types/credentials.tsnew file mode 100644index 0000000000..3e2ea9d98b--- /dev/null+++ b/web/packages/next/types/credentials.ts@@ -0,0 +1,18 @@+import { nullToUndefined } from "@/utils/transform";+import { z } from "zod";++// TODO: Provide types+export const KeyAttributes = z.object({});++/**+ * The result of a successful two factor verification (totp or passkey).+ */+export const TwoFactorAuthorizationResponse = z.object({+ id: z.number(),+ keyAttributes: KeyAttributes.nullish().transform(nullToUndefined),+ encryptedToken: z.string().nullish().transform(nullToUndefined),+});++export type TwoFactorAuthorizationResponse = z.infer<+ typeof TwoFactorAuthorizationResponse+>;