Skip to content

Commit 985f565

Browse files
committed
fix(routes): Remove deprecated non-MFA endpoints and redundant session checks
1 parent 7564e57 commit 985f565

34 files changed

Lines changed: 1384 additions & 3791 deletions

packages/functional-tests/lib/testAccountTracker.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ export class TestAccountTracker {
340340
}
341341

342342
if (has2FA) {
343-
// TODO: `deleteTotpToken` is deprecated, use `deleteTotpTokenWithJwt` instead
344-
// https://mozilla-hub.atlassian.net/browse/FXA-12629
345-
await this.target.authClient.deleteTotpToken(sessionToken);
343+
// Get MFA JWT for 2FA scope to delete TOTP
344+
const mfaJwt = await this.getMfaJwtForScope('2fa', sessionToken, account.email);
345+
await this.target.authClient.deleteTotpTokenWithJwt(mfaJwt);
346346
}
347347

348348
await this.target.authClient.accountDestroy(
@@ -387,6 +387,39 @@ export class TestAccountTracker {
387387
await this.target.authClient.verifyTotpCode(sessionToken, code);
388388
}
389389

390+
/**
391+
* Gets an MFA JWT for a specific scope by requesting and verifying an OTP.
392+
* This is used for operations that require MFA authentication.
393+
*/
394+
private async getMfaJwtForScope(
395+
scope: MfaScope,
396+
sessionToken: string,
397+
email: string
398+
): Promise<string> {
399+
const { status } = await this.target.authClient.mfaRequestOtp(
400+
sessionToken,
401+
scope
402+
);
403+
if (status !== 'success') {
404+
throw new Error(`Failed to request MFA OTP for scope: ${scope}`);
405+
}
406+
407+
const code = await this.target.emailClient.getVerifyAccountChangeCode(email);
408+
409+
const { accessToken } = await this.target.authClient.mfaOtpVerify(
410+
sessionToken,
411+
code,
412+
scope
413+
);
414+
if (!accessToken) {
415+
throw new Error(
416+
`Failed to get MFA JWT for scope: ${scope}. No accessToken returned`
417+
);
418+
}
419+
420+
return accessToken;
421+
}
422+
390423
/**
391424
* Clears the MFA JWT cache of tokens for the given scopes.
392425
*

packages/fxa-auth-client/lib/client.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,19 +1941,6 @@ export default class AuthClient {
19411941
return this.jwtPost('/mfa/recovery_email', jwt, { email }, headers);
19421942
}
19431943

1944-
async recoveryEmailDestroy(
1945-
sessionToken: hexstring,
1946-
email: string,
1947-
headers?: Headers
1948-
) {
1949-
return this.sessionPost(
1950-
'/recovery_email/destroy',
1951-
sessionToken,
1952-
{ email },
1953-
headers
1954-
);
1955-
}
1956-
19571944
async recoveryEmailDestroyWithJwt(
19581945
jwt: string,
19591946
email: string,
@@ -2315,19 +2302,6 @@ export default class AuthClient {
23152302
return this.jwtPost('/mfa/totp/replace/confirm', jwt, { code }, headers);
23162303
}
23172304

2318-
/**
2319-
* @deprecated Use deleteTotpTokenWithJwt instead
2320-
*
2321-
* Disables 2FA Protection on the account.
2322-
*
2323-
* @param sessionToken - required, must be a verified session token
2324-
* @param headers - Optional additional headers for the request
2325-
* @returns A promise that resolves when the 2FA has been removed
2326-
*/
2327-
async deleteTotpToken(sessionToken: hexstring, headers?: Headers) {
2328-
return this.sessionPost('/totp/destroy', sessionToken, {}, headers);
2329-
}
2330-
23312305
/**
23322306
* Disables 2FA Protection on the account.
23332307
*

packages/fxa-auth-server/lib/routes/attached-clients.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module.exports = (log, db, devices, clientUtils) => {
123123
...DEVICES_AND_SESSIONS_DOC.ACCOUNT_ATTACHED_CLIENT_DESTROY_POST,
124124
auth: {
125125
strategy: 'verifiedSessionToken',
126-
payload: 'false',
126+
payload: false,
127127
},
128128
validate: {
129129
payload: isA

0 commit comments

Comments
 (0)