π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Document
Manav Rathiba20fd476333
diff --git a/web/apps/accounts/src/pages/passkeys/finish.tsx b/web/apps/accounts/src/pages/passkeys/finish.tsxindex 866dcf9e3a..d59dd45597 100644--- a/web/apps/accounts/src/pages/passkeys/finish.tsx+++ b/web/apps/accounts/src/pages/passkeys/finish.tsx@@ -1,3 +1,4 @@import Page from "@ente/accounts/pages/passkeys/finish";+// See: [Note: Finish passkey flow in the requesting app]export default Page;diff --git a/web/packages/accounts/pages/passkeys/finish.tsx b/web/packages/accounts/pages/passkeys/finish.tsxindex d5347f835d..876a758c4c 100644--- a/web/packages/accounts/pages/passkeys/finish.tsx+++ b/web/packages/accounts/pages/passkeys/finish.tsx@@ -6,6 +6,13 @@ import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";import { useRouter } from "next/router";import React, { useEffect } from "react";+/**+ * [Note: Finish passkey flow in the requesting app]+ *+ * The passkey finish step needs to happen in the context of the client which+ * invoked the passkey flow since it needs to save the obtained credentials+ * in local storage (which is tied to the current origin).+ */const Page: React.FC = () => {const router = useRouter();@@ -16,20 +23,8 @@ const Page: React.FC = () => {if (!response) return;- // decode response- const decodedResponse = JSON.parse(atob(response));-- // only one will be present- // token only during fresh signup- // encryptedToken othw- const { keyAttributes, encryptedToken, token, id } = decodedResponse;- setData(LS_KEYS.USER, {- ...getData(LS_KEYS.USER),- token,- encryptedToken,- id,- });- setData(LS_KEYS.KEY_ATTRIBUTES, keyAttributes);+ saveCredentials(response);+const redirectURL = InMemoryStore.get(MS_KEYS.REDIRECT_URL);InMemoryStore.delete(MS_KEYS.REDIRECT_URL);router.push(redirectURL ?? PAGES.ROOT);@@ -47,3 +42,35 @@ const Page: React.FC = () => {};export default Page;++/**+ * Extract credentials from a successful passkey flow "response" query parameter+ * and save them to local storage for use by subsequent steps (or normal+ * functioning) of the app.+ *+ * @param response The string that is passed as the response query parameter to+ * us (we're the final "finish" page in the passkey flow).+ */+const saveCredentials = (response: string) => {+ // Decode response string.+ const decodedResponse = JSON.parse(atob(response));++ // Only one of `encryptedToken` or `token` will be present depending on the+ // account's lifetime:+ //+ // - The plaintext "token" will be passed during fresh signups, where we+ // don't yet have keys to encrypt it, the account itself is being created+ // as we go through this flow.+ //+ //+ // - The encrypted `encryptedToken` will be present otherwise (i.e. if the+ // user is signing into an existing account).+ const { keyAttributes, encryptedToken, token, id } = decodedResponse;+ setData(LS_KEYS.USER, {+ ...getData(LS_KEYS.USER),+ token,+ encryptedToken,+ id,+ });+ setData(LS_KEYS.KEY_ATTRIBUTES, keyAttributes);+};