mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
chore(2fa recovery code): [PM-18175] Remove feature flag and old recovery flow
This commit is contained in:
@@ -7,17 +7,11 @@ import {
|
||||
PasswordLoginCredentials,
|
||||
LoginSuccessHandlerService,
|
||||
} from "@bitwarden/auth/common";
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-provider-type";
|
||||
import { TokenTwoFactorRequest } from "@bitwarden/common/auth/models/request/identity-token/token-two-factor.request";
|
||||
import { TwoFactorRecoveryRequest } from "@bitwarden/common/auth/models/request/two-factor-recovery.request";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { ToastService } from "@bitwarden/components";
|
||||
import { KeyService } from "@bitwarden/key-management";
|
||||
import { NewDeviceVerificationNoticeService } from "@bitwarden/vault";
|
||||
|
||||
@Component({
|
||||
@@ -36,32 +30,18 @@ export class RecoverTwoFactorComponent implements OnInit {
|
||||
*/
|
||||
recoveryCodeMessage = "";
|
||||
|
||||
/**
|
||||
* Whether the recovery code login feature flag is enabled
|
||||
*/
|
||||
private recoveryCodeLoginFeatureFlagEnabled = false;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private apiService: ApiService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private i18nService: I18nService,
|
||||
private keyService: KeyService,
|
||||
private loginStrategyService: LoginStrategyServiceAbstraction,
|
||||
private toastService: ToastService,
|
||||
private configService: ConfigService,
|
||||
private loginSuccessHandlerService: LoginSuccessHandlerService,
|
||||
private logService: LogService,
|
||||
private newDeviceVerificationNoticeService: NewDeviceVerificationNoticeService,
|
||||
) {}
|
||||
|
||||
async ngOnInit() {
|
||||
this.recoveryCodeLoginFeatureFlagEnabled = await this.configService.getFeatureFlag(
|
||||
FeatureFlag.RecoveryCodeLogin,
|
||||
);
|
||||
this.recoveryCodeMessage = this.recoveryCodeLoginFeatureFlagEnabled
|
||||
? this.i18nService.t("logInBelowUsingYourSingleUseRecoveryCode")
|
||||
: this.i18nService.t("recoverAccountTwoStepDesc");
|
||||
this.recoveryCodeMessage = this.i18nService.t("logInBelowUsingYourSingleUseRecoveryCode");
|
||||
}
|
||||
|
||||
get email(): string {
|
||||
@@ -85,38 +65,25 @@ export class RecoverTwoFactorComponent implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
const request = new TwoFactorRecoveryRequest();
|
||||
request.recoveryCode = this.recoveryCode.replace(/\s/g, "").toLowerCase();
|
||||
request.email = this.email.trim().toLowerCase();
|
||||
const key = await this.loginStrategyService.makePreloginKey(this.masterPassword, request.email);
|
||||
request.masterPasswordHash = await this.keyService.hashMasterKey(this.masterPassword, key);
|
||||
const email = this.email.trim().toLowerCase();
|
||||
const recoveryCode = this.recoveryCode.replace(/\s/g, "").toLowerCase();
|
||||
|
||||
if (this.recoveryCodeLoginFeatureFlagEnabled) {
|
||||
await this.handleRecoveryLogin(request);
|
||||
} else {
|
||||
await this.apiService.postTwoFactorRecover(request);
|
||||
this.toastService.showToast({
|
||||
variant: "success",
|
||||
title: "",
|
||||
message: this.i18nService.t("twoStepRecoverDisabled"),
|
||||
});
|
||||
await this.router.navigate(["/"]);
|
||||
}
|
||||
await this.loginWithRecoveryCode(email, recoveryCode);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles the login process after a successful account recovery.
|
||||
*/
|
||||
private async handleRecoveryLogin(request: TwoFactorRecoveryRequest) {
|
||||
private async loginWithRecoveryCode(email: string, recoveryCode: string) {
|
||||
// Build two-factor request to pass into PasswordLoginCredentials request using the 2FA recovery code and RecoveryCode type
|
||||
const twoFactorRequest: TokenTwoFactorRequest = {
|
||||
provider: TwoFactorProviderType.RecoveryCode,
|
||||
token: request.recoveryCode,
|
||||
token: recoveryCode,
|
||||
remember: false,
|
||||
};
|
||||
|
||||
const credentials = new PasswordLoginCredentials(
|
||||
request.email,
|
||||
email,
|
||||
this.masterPassword,
|
||||
"",
|
||||
twoFactorRequest,
|
||||
@@ -148,7 +115,7 @@ export class RecoverTwoFactorComponent implements OnInit {
|
||||
} catch (error) {
|
||||
// If login errors, redirect to login page per product. Don't show error
|
||||
this.logService.error("Error logging in automatically: ", (error as Error).message);
|
||||
await this.router.navigate(["/login"], { queryParams: { email: request.email } });
|
||||
await this.router.navigate(["/login"], { queryParams: { email: email } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user