1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-06 09:20:43 +01:00

[Reset Password v1] Refactor ForcePasswordReset into AuthResult (#481)

This commit is contained in:
Vincent Salucci 2021-09-17 10:53:50 -05:00 committed by GitHub
parent 5cec31f871
commit 16e998e664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 0 deletions

View File

@ -39,9 +39,11 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
onSuccessfulLogin: () => Promise<any>; onSuccessfulLogin: () => Promise<any>;
onSuccessfulLoginNavigate: () => Promise<any>; onSuccessfulLoginNavigate: () => Promise<any>;
onSuccessfulLoginTwoFactorNavigate: () => Promise<any>; onSuccessfulLoginTwoFactorNavigate: () => Promise<any>;
onSuccessfulLoginForceResetNavigate: () => Promise<any>;
protected twoFactorRoute = '2fa'; protected twoFactorRoute = '2fa';
protected successRoute = 'vault'; protected successRoute = 'vault';
protected forcePasswordResetRoute = 'update-temp-password';
constructor(protected authService: AuthService, protected router: Router, constructor(protected authService: AuthService, protected router: Router,
platformUtilsService: PlatformUtilsService, i18nService: I18nService, platformUtilsService: PlatformUtilsService, i18nService: I18nService,
@ -103,6 +105,12 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
} else { } else {
this.router.navigate([this.twoFactorRoute]); this.router.navigate([this.twoFactorRoute]);
} }
} else if (response.forcePasswordReset) {
if (this.onSuccessfulLoginForceResetNavigate != null) {
this.onSuccessfulLoginForceResetNavigate();
} else {
this.router.navigate([this.forcePasswordResetRoute]);
}
} else { } else {
const disableFavicon = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey); const disableFavicon = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
await this.stateService.save(ConstantsService.disableFaviconKey, !!disableFavicon); await this.stateService.save(ConstantsService.disableFaviconKey, !!disableFavicon);

View File

@ -31,10 +31,12 @@ export class SsoComponent {
onSuccessfulLoginNavigate: () => Promise<any>; onSuccessfulLoginNavigate: () => Promise<any>;
onSuccessfulLoginTwoFactorNavigate: () => Promise<any>; onSuccessfulLoginTwoFactorNavigate: () => Promise<any>;
onSuccessfulLoginChangePasswordNavigate: () => Promise<any>; onSuccessfulLoginChangePasswordNavigate: () => Promise<any>;
onSuccessfulLoginForceResetNavigate: () => Promise<any>;
protected twoFactorRoute = '2fa'; protected twoFactorRoute = '2fa';
protected successRoute = 'lock'; protected successRoute = 'lock';
protected changePasswordRoute = 'set-password'; protected changePasswordRoute = 'set-password';
protected forcePasswordResetRoute = 'update-temp-password';
protected clientId: string; protected clientId: string;
protected redirectUri: string; protected redirectUri: string;
protected state: string; protected state: string;
@ -161,6 +163,12 @@ export class SsoComponent {
}, },
}); });
} }
} else if (response.forcePasswordReset) {
if (this.onSuccessfulLoginForceResetNavigate != null) {
this.onSuccessfulLoginForceResetNavigate();
} else {
this.router.navigate([this.forcePasswordResetRoute]);
}
} else { } else {
const disableFavicon = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey); const disableFavicon = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
await this.stateService.save(ConstantsService.disableFaviconKey, !!disableFavicon); await this.stateService.save(ConstantsService.disableFaviconKey, !!disableFavicon);

View File

@ -185,6 +185,9 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
if (response.resetMasterPassword) { if (response.resetMasterPassword) {
this.successRoute = 'set-password'; this.successRoute = 'set-password';
} }
if (response.forcePasswordReset) {
this.successRoute = 'update-temp-password';
}
if (this.onSuccessfulLoginNavigate != null) { if (this.onSuccessfulLoginNavigate != null) {
this.onSuccessfulLoginNavigate(); this.onSuccessfulLoginNavigate();
} else { } else {

View File

@ -4,5 +4,6 @@ export class AuthResult {
twoFactor: boolean = false; twoFactor: boolean = false;
captchaSiteKey: string = ''; captchaSiteKey: string = '';
resetMasterPassword: boolean = false; resetMasterPassword: boolean = false;
forcePasswordReset: boolean = false;
twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string; }> = null; twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string; }> = null;
} }

View File

@ -14,6 +14,7 @@ export class IdentityTokenResponse extends BaseResponse {
twoFactorToken: string; twoFactorToken: string;
kdf: KdfType; kdf: KdfType;
kdfIterations: number; kdfIterations: number;
forcePasswordReset: boolean;
constructor(response: any) { constructor(response: any) {
super(response); super(response);
@ -28,5 +29,6 @@ export class IdentityTokenResponse extends BaseResponse {
this.twoFactorToken = this.getResponseProperty('TwoFactorToken'); this.twoFactorToken = this.getResponseProperty('TwoFactorToken');
this.kdf = this.getResponseProperty('Kdf'); this.kdf = this.getResponseProperty('Kdf');
this.kdfIterations = this.getResponseProperty('KdfIterations'); this.kdfIterations = this.getResponseProperty('KdfIterations');
this.forcePasswordReset = this.getResponseProperty('ForcePasswordReset');
} }
} }

View File

@ -340,6 +340,7 @@ export class AuthService implements AuthServiceAbstraction {
const tokenResponse = response as IdentityTokenResponse; const tokenResponse = response as IdentityTokenResponse;
result.resetMasterPassword = tokenResponse.resetMasterPassword; result.resetMasterPassword = tokenResponse.resetMasterPassword;
result.forcePasswordReset = tokenResponse.forcePasswordReset;
if (tokenResponse.twoFactorToken != null) { if (tokenResponse.twoFactorToken != null) {
await this.tokenService.setTwoFactorToken(tokenResponse.twoFactorToken, email); await this.tokenService.setTwoFactorToken(tokenResponse.twoFactorToken, email);
} }