mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-23 21:31:29 +01:00
add handleMigrateEncryptionKey to default and web service
This commit is contained in:
parent
983cee8af6
commit
19acf12900
@ -1,11 +1,12 @@
|
||||
import { inject } from "@angular/core";
|
||||
import { UrlTree } from "@angular/router";
|
||||
import { Router, UrlTree } from "@angular/router";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { DefaultLoginService, LoginService, PasswordPolicies } from "@bitwarden/auth/angular";
|
||||
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 { 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 { flagEnabled } from "../../../../../utils/flags";
|
||||
@ -17,6 +18,7 @@ export class WebLoginService extends DefaultLoginService implements LoginService
|
||||
logService = inject(LogService);
|
||||
policyApiService = inject(PolicyApiServiceAbstraction);
|
||||
policyService = inject(InternalPolicyService);
|
||||
router = inject(Router);
|
||||
routerService = inject(RouterService);
|
||||
|
||||
getShowPasswordlessFlag(): boolean {
|
||||
@ -67,4 +69,12 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@ -332,8 +332,7 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit,
|
||||
await this.loginEmailService.saveEmailSettings();
|
||||
}
|
||||
|
||||
// Legacy accounts used the master key to encrypt data. Migration is required
|
||||
// but only performed on web
|
||||
// Legacy accounts used the master key to encrypt data. Migration is required but only performed on web
|
||||
protected async handleMigrateEncryptionKey(result: AuthResult): Promise<boolean> {
|
||||
if (!result.requiresEncryptionKeyMigration) {
|
||||
return false;
|
||||
|
@ -1,8 +1,17 @@
|
||||
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 { ToastService } from "@bitwarden/components";
|
||||
|
||||
import { LoginService, PasswordPolicies } from "./login.service";
|
||||
|
||||
export class DefaultLoginService implements LoginService {
|
||||
constructor(
|
||||
protected i18nService: I18nService,
|
||||
protected toastService: ToastService,
|
||||
) {}
|
||||
|
||||
getShowPasswordlessFlag(): boolean {
|
||||
return null;
|
||||
}
|
||||
@ -14,4 +23,18 @@ export class DefaultLoginService implements LoginService {
|
||||
async getOrgPolicies(): Promise<PasswordPolicies | 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;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<form [bitSubmit]="submit" [formGroup]="formGroup">
|
||||
<form [bitSubmit]="submit.bind(null, false)" [formGroup]="formGroup">
|
||||
<!-------------------------
|
||||
UI STATE 1: Email Entry
|
||||
-------------------------->
|
||||
|
@ -5,11 +5,17 @@ import { ActivatedRoute, Router, RouterModule } from "@angular/router";
|
||||
import { first, firstValueFrom, Subject, take, takeUntil } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { LoginEmailServiceAbstraction, RegisterRouteService } from "@bitwarden/auth/common";
|
||||
import {
|
||||
LoginEmailServiceAbstraction,
|
||||
LoginStrategyServiceAbstraction,
|
||||
PasswordLoginCredentials,
|
||||
RegisterRouteService,
|
||||
} from "@bitwarden/auth/common";
|
||||
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
|
||||
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
|
||||
import { CaptchaIFrame } from "@bitwarden/common/auth/captcha-iframe";
|
||||
import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/force-set-password-reason";
|
||||
import { ClientType } from "@bitwarden/common/enums";
|
||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||
@ -85,6 +91,7 @@ export class LoginComponentV2 implements OnInit, OnDestroy {
|
||||
private i18nService: I18nService,
|
||||
private loginEmailService: LoginEmailServiceAbstraction,
|
||||
private loginService: LoginService,
|
||||
private loginStrategyService: LoginStrategyServiceAbstraction,
|
||||
private ngZone: NgZone,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private registerRouteService: RegisterRouteService,
|
||||
@ -137,7 +144,42 @@ export class LoginComponentV2 implements OnInit, OnDestroy {
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
submit = async () => {};
|
||||
submit = async (showToast: boolean): Promise<void> => {
|
||||
const data = this.formGroup.value;
|
||||
|
||||
await this.setupCaptcha();
|
||||
|
||||
this.formGroup.markAllAsTouched();
|
||||
|
||||
// Web specific (start)
|
||||
if (this.formGroup.invalid && !showToast) {
|
||||
return;
|
||||
}
|
||||
// Web specific (end)
|
||||
|
||||
const credentials = new PasswordLoginCredentials(
|
||||
data.email,
|
||||
data.masterPassword,
|
||||
this.captchaToken,
|
||||
null,
|
||||
);
|
||||
|
||||
const response = await this.loginStrategyService.logIn(credentials);
|
||||
|
||||
await this.saveEmailSettings();
|
||||
|
||||
if (this.handleCaptchaRequired(response)) {
|
||||
return;
|
||||
} else if (await this.handleMigrateEncryptionKey(response)) {
|
||||
return;
|
||||
} else if (response.requiresTwoFactor) {
|
||||
// code ...
|
||||
} else if (response.forcePasswordReset != ForceSetPasswordReason.None) {
|
||||
// code ...
|
||||
} else {
|
||||
// code ...
|
||||
}
|
||||
};
|
||||
|
||||
protected async setupCaptcha() {
|
||||
const env = await firstValueFrom(this.environmentService.environment$);
|
||||
|
@ -2,6 +2,7 @@ import { UrlTree } from "@angular/router";
|
||||
|
||||
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
|
||||
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||
import { AuthResult } from "@bitwarden/common/auth/models/domain/auth-result";
|
||||
|
||||
export interface PasswordPolicies {
|
||||
policies: Policy[];
|
||||
@ -10,6 +11,8 @@ export interface PasswordPolicies {
|
||||
}
|
||||
|
||||
export abstract class LoginService {
|
||||
handleMigrateEncryptionKey: (result: AuthResult) => Promise<boolean>;
|
||||
|
||||
// Web specific
|
||||
getShowPasswordlessFlag: () => boolean;
|
||||
getOrgPolicies: () => Promise<PasswordPolicies | null>;
|
||||
|
Loading…
Reference in New Issue
Block a user