mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
* [PM-2135] feat: create new user-verification module
* [PM-2136] feat: add ability to remove form field bottom margin
(cherry picked from commit 05925ff77ed47f3865c2aecade8271390d9e2fa6)
* [PM-2135] feat: refactor user-verification component
* [PM-2135] feat: refactor user-verification-prompt
* [PM-2135] feat: use form validation in prompt
* [PM-2135] feat: change autofocus target
* [PM-2135] chore: clean up old code
* [PM-2135] feat: allow user verification to show invalid password error
* [PM-2135] feat: hack mark as touched to get error to display
* [PM-2135] chore: move to auth
* [PM-2135] fix: hardcoded dialog buttons
* [PM-2135] feat: add onDestroy handler
* [PM-2135] fix: remove unecessary directive input
* [PM-2135] feat: add password toggle
* [PM-2135] chore: add hack comment
* [PM-2135] chore: move services to auth folder and rename
* [PM-2135] fix: show correct error messages
* [PM-2135] fix: re-add non-existant files to whitelist
I honestly don't know why the linter is complaining about this
* Fix capital letters whitelist
* [PM-2135] chore: remove rows that were mistakenly added during merge from master
* [PM-2135] chore: remove rows that were mistakenly added during merge from master
* [PM-2135] feat: disable built-in browser validations
* Revert "[PM-2135] feat: disable built-in browser validations"
This reverts commit 969f75822a.
---------
Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
76 lines
2.9 KiB
TypeScript
76 lines
2.9 KiB
TypeScript
import { Component, EventEmitter, Input, Output } from "@angular/core";
|
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
|
|
import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-provider-type";
|
|
import { VerificationType } from "@bitwarden/common/auth/enums/verification-type";
|
|
import { SecretVerificationRequest } from "@bitwarden/common/auth/models/request/secret-verification.request";
|
|
import { AuthResponse } from "@bitwarden/common/auth/types/auth-response";
|
|
import { TwoFactorResponse } from "@bitwarden/common/auth/types/two-factor-response";
|
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
|
import { Verification } from "@bitwarden/common/types/verification";
|
|
|
|
@Component({
|
|
selector: "app-two-factor-verify",
|
|
templateUrl: "two-factor-verify.component.html",
|
|
})
|
|
export class TwoFactorVerifyComponent {
|
|
@Input() type: TwoFactorProviderType;
|
|
@Input() organizationId: string;
|
|
@Output() onAuthed = new EventEmitter<AuthResponse<TwoFactorResponse>>();
|
|
|
|
secret: Verification;
|
|
formPromise: Promise<TwoFactorResponse>;
|
|
|
|
constructor(
|
|
private apiService: ApiService,
|
|
private logService: LogService,
|
|
private userVerificationService: UserVerificationService
|
|
) {}
|
|
|
|
async submit() {
|
|
let hashedSecret: string;
|
|
|
|
try {
|
|
this.formPromise = this.userVerificationService.buildRequest(this.secret).then((request) => {
|
|
hashedSecret =
|
|
this.secret.type === VerificationType.MasterPassword
|
|
? request.masterPasswordHash
|
|
: request.otp;
|
|
return this.apiCall(request);
|
|
});
|
|
|
|
const response = await this.formPromise;
|
|
this.onAuthed.emit({
|
|
response: response,
|
|
secret: hashedSecret,
|
|
verificationType: this.secret.type,
|
|
});
|
|
} catch (e) {
|
|
this.logService.error(e);
|
|
}
|
|
}
|
|
|
|
private apiCall(request: SecretVerificationRequest): Promise<TwoFactorResponse> {
|
|
switch (this.type) {
|
|
case -1 as TwoFactorProviderType:
|
|
return this.apiService.getTwoFactorRecover(request);
|
|
case TwoFactorProviderType.Duo:
|
|
case TwoFactorProviderType.OrganizationDuo:
|
|
if (this.organizationId != null) {
|
|
return this.apiService.getTwoFactorOrganizationDuo(this.organizationId, request);
|
|
} else {
|
|
return this.apiService.getTwoFactorDuo(request);
|
|
}
|
|
case TwoFactorProviderType.Email:
|
|
return this.apiService.getTwoFactorEmail(request);
|
|
case TwoFactorProviderType.WebAuthn:
|
|
return this.apiService.getTwoFactorWebAuthn(request);
|
|
case TwoFactorProviderType.Authenticator:
|
|
return this.apiService.getTwoFactorAuthenticator(request);
|
|
case TwoFactorProviderType.Yubikey:
|
|
return this.apiService.getTwoFactorYubiKey(request);
|
|
}
|
|
}
|
|
}
|