[web] Passkey fixes (#1866)

@ua741 Not sure if passkey code is supposed to work on web yet, but I
was doing an unrelated change and noticed that clicking passkeys didn't
even try to redirect to accounts. I don't have a test setup for
passkeys, so don't know if these changes are 100% correct, but at least
now it redirects to accounts. Can test fully when doing final
integration.

- Use correct origin for passkey API requests
- Fix key length error
- Fix param name to match server
- Pass the token instead of a query param
This commit is contained in:
Manav Rathi 2024-05-26 18:55:11 +05:30 committed by GitHub
commit 4bcb765810
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -14,6 +14,7 @@ import {
ACCOUNTS_PAGES, ACCOUNTS_PAGES,
PHOTOS_PAGES as PAGES, PHOTOS_PAGES as PAGES,
} from "@ente/shared/constants/pages"; } from "@ente/shared/constants/pages";
import ComlinkCryptoWorker from "@ente/shared/crypto";
import { getRecoveryKey } from "@ente/shared/crypto/helpers"; import { getRecoveryKey } from "@ente/shared/crypto/helpers";
import { import {
encryptToB64, encryptToB64,
@ -494,9 +495,10 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
const resetSecret = await generateEncryptionKey(); const resetSecret = await generateEncryptionKey();
const cryptoWorker = await ComlinkCryptoWorker.getInstance();
const encryptionResult = await encryptToB64( const encryptionResult = await encryptToB64(
resetSecret, resetSecret,
recoveryKey, await cryptoWorker.fromHex(recoveryKey),
); );
await configurePasskeyRecovery( await configurePasskeyRecovery(

View file

@ -1,6 +1,7 @@
import log from "@/next/log"; import log from "@/next/log";
import { CustomError } from "@ente/shared/error"; import { CustomError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService"; import HTTPService from "@ente/shared/network/HTTPService";
import { getEndpoint } from "@ente/shared/network/api";
import { getToken } from "@ente/shared/storage/localStorage/helpers"; import { getToken } from "@ente/shared/storage/localStorage/helpers";
export const isPasskeyRecoveryEnabled = async () => { export const isPasskeyRecoveryEnabled = async () => {
@ -8,7 +9,7 @@ export const isPasskeyRecoveryEnabled = async () => {
const token = getToken(); const token = getToken();
const resp = await HTTPService.get( const resp = await HTTPService.get(
"/users/two-factor/recovery-status", `${getEndpoint()}/users/two-factor/recovery-status`,
{}, {},
{ {
"X-Auth-Token": token, "X-Auth-Token": token,
@ -28,19 +29,20 @@ export const isPasskeyRecoveryEnabled = async () => {
export const configurePasskeyRecovery = async ( export const configurePasskeyRecovery = async (
secret: string, secret: string,
userEncryptedSecret: string, userSecretCipher: string,
userSecretNonce: string, userSecretNonce: string,
) => { ) => {
try { try {
const token = getToken(); const token = getToken();
const resp = await HTTPService.post( const resp = await HTTPService.post(
"/users/two-factor/passkeys/configure-recovery", `${getEndpoint()}/users/two-factor/passkeys/configure-recovery`,
{ {
secret, secret,
userEncryptedSecret, userSecretCipher,
userSecretNonce, userSecretNonce,
}, },
undefined,
{ {
"X-Auth-Token": token, "X-Auth-Token": token,
}, },