mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
refactor handleMigrateEncryptionKey()
This commit is contained in:
@@ -6,7 +6,6 @@ import { DefaultLoginService, LoginService, PasswordPolicies } from "@bitwarden/
|
|||||||
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
||||||
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||||
import { AuthResult } from "@bitwarden/common/auth/models/domain/auth-result";
|
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
|
|
||||||
import { flagEnabled } from "../../../../../utils/flags";
|
import { flagEnabled } from "../../../../../utils/flags";
|
||||||
@@ -69,12 +68,4 @@ export class WebLoginService extends DefaultLoginService implements LoginService
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override async handleMigrateEncryptionKey(result: AuthResult): Promise<boolean> {
|
|
||||||
if (!result.requiresEncryptionKeyMigration) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
await this.router.navigate(["migrate-legacy-encryption"]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { UrlTree } from "@angular/router";
|
import { UrlTree } from "@angular/router";
|
||||||
|
|
||||||
import { AuthResult } from "@bitwarden/common/auth/models/domain/auth-result";
|
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { ToastService } from "@bitwarden/components";
|
import { ToastService } from "@bitwarden/components";
|
||||||
|
|
||||||
@@ -23,18 +22,4 @@ export class DefaultLoginService implements LoginService {
|
|||||||
async getOrgPolicies(): Promise<PasswordPolicies | null> {
|
async getOrgPolicies(): Promise<PasswordPolicies | null> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy accounts used the master key to encrypt data. Migration is required but only performed on web
|
|
||||||
async handleMigrateEncryptionKey(result: AuthResult): Promise<boolean> {
|
|
||||||
if (!result.requiresEncryptionKeyMigration) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.toastService.showToast({
|
|
||||||
variant: "error",
|
|
||||||
title: this.i18nService.t("errorOccured"),
|
|
||||||
message: this.i18nService.t("encryptionKeyMigrationRequired"),
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,8 +169,18 @@ export class LoginComponentV2 implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
if (this.handleCaptchaRequired(authResult)) {
|
if (this.handleCaptchaRequired(authResult)) {
|
||||||
return;
|
return;
|
||||||
} else if (await this.loginService.handleMigrateEncryptionKey(authResult)) {
|
} else if (authResult.requiresEncryptionKeyMigration) {
|
||||||
return;
|
/* Legacy accounts used the master key to encrypt data.
|
||||||
|
Migration is required but only performed on Web. */
|
||||||
|
if (this.clientType === ClientType.Web) {
|
||||||
|
await this.router.navigate(["migrate-legacy-encryption"]);
|
||||||
|
} else {
|
||||||
|
this.toastService.showToast({
|
||||||
|
variant: "error",
|
||||||
|
title: this.i18nService.t("errorOccured"),
|
||||||
|
message: this.i18nService.t("encryptionKeyMigrationRequired"),
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (authResult.requiresTwoFactor) {
|
} else if (authResult.requiresTwoFactor) {
|
||||||
await this.router.navigate(["2fa"]);
|
await this.router.navigate(["2fa"]);
|
||||||
} else if (authResult.forcePasswordReset != ForceSetPasswordReason.None) {
|
} else if (authResult.forcePasswordReset != ForceSetPasswordReason.None) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { UrlTree } from "@angular/router";
|
|||||||
|
|
||||||
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
|
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
|
||||||
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||||
import { AuthResult } from "@bitwarden/common/auth/models/domain/auth-result";
|
|
||||||
|
|
||||||
export interface PasswordPolicies {
|
export interface PasswordPolicies {
|
||||||
policies: Policy[];
|
policies: Policy[];
|
||||||
@@ -11,8 +10,6 @@ export interface PasswordPolicies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export abstract class LoginService {
|
export abstract class LoginService {
|
||||||
handleMigrateEncryptionKey: (result: AuthResult) => Promise<boolean>;
|
|
||||||
|
|
||||||
// Web specific
|
// Web specific
|
||||||
getShowPasswordlessFlag: () => boolean;
|
getShowPasswordlessFlag: () => boolean;
|
||||||
getOrgPolicies: () => Promise<PasswordPolicies | null>;
|
getOrgPolicies: () => Promise<PasswordPolicies | null>;
|
||||||
|
|||||||
Reference in New Issue
Block a user