Skip to content

Commit

Permalink
Auth/PM-15115 - New LoginComponent - Remove Captcha (#12077)
Browse files Browse the repository at this point in the history
* PM-15115 - Captcha being deprecated so remove from new UI refreshed login component + start putting deprecated comments on some things.

* PM-15115 - Add Jira ticket to TODOs per best practice
  • Loading branch information
JaredSnider-Bitwarden authored Nov 22, 2024
1 parent 2ee14ba commit 493f81a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 67 deletions.
8 changes: 0 additions & 8 deletions libs/auth/src/angular/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@
{{ "getMasterPasswordHint" | i18n }}
</a>

<!-- Captcha iframe -->
<iframe
[ngClass]="{ 'tw-hidden': !showCaptcha() }"
id="hcaptcha_iframe"
height="80"
sandbox="allow-scripts allow-same-origin"
></iframe>

<div class="tw-grid tw-gap-3">
<!-- Submit button to Login with Master Password -->
<button type="submit" bitButton bitFormButton block buttonType="primary">
Expand Down
61 changes: 2 additions & 59 deletions libs/auth/src/angular/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from "@angular/common";
import { Component, ElementRef, Input, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core";
import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core";
import { FormBuilder, FormControl, ReactiveFormsModule, Validators } from "@angular/forms";
import { ActivatedRoute, Router, RouterModule } from "@angular/router";
import { firstValueFrom, Subject, take, takeUntil, tap } from "rxjs";
Expand All @@ -15,7 +15,6 @@ import { InternalPolicyService } from "@bitwarden/common/admin-console/abstracti
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 { AuthResult } from "@bitwarden/common/auth/models/domain/auth-result";
import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/force-set-password-reason";
import { ClientType, HttpStatusCode } from "@bitwarden/common/enums";
Expand All @@ -24,7 +23,6 @@ import { ErrorResponse } from "@bitwarden/common/models/response/error.response"
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
Expand Down Expand Up @@ -73,14 +71,11 @@ export enum LoginUiState {
})
export class LoginComponent implements OnInit, OnDestroy {
@ViewChild("masterPasswordInputRef") masterPasswordInputRef: ElementRef;
@Input() captchaSiteKey: string = null;

private destroy$ = new Subject<void>();
private enforcedMasterPasswordOptions: MasterPasswordPolicyOptions = undefined;
readonly Icons = { WaveIcon, VaultIcon };

captcha: CaptchaIFrame;
captchaToken: string = null;
clientType: ClientType;
ClientType = ClientType;
LoginUiState = LoginUiState;
Expand Down Expand Up @@ -118,7 +113,6 @@ export class LoginComponent implements OnInit, OnDestroy {
private appIdService: AppIdService,
private broadcasterService: BroadcasterService,
private devicesApiService: DevicesApiServiceAbstraction,
private environmentService: EnvironmentService,
private formBuilder: FormBuilder,
private i18nService: I18nService,
private loginEmailService: LoginEmailServiceAbstraction,
Expand Down Expand Up @@ -193,8 +187,6 @@ export class LoginComponent implements OnInit, OnDestroy {

const { email, masterPassword } = this.formGroup.value;

await this.setupCaptcha();

this.formGroup.markAllAsTouched();
if (this.formGroup.invalid) {
return;
Expand All @@ -203,7 +195,7 @@ export class LoginComponent implements OnInit, OnDestroy {
const credentials = new PasswordLoginCredentials(
email,
masterPassword,
this.captchaToken,
null, // captcha no longer used in new login / registration scenarios
null,
);

Expand All @@ -212,13 +204,6 @@ export class LoginComponent implements OnInit, OnDestroy {

await this.saveEmailSettings();
await this.handleAuthResult(authResult);

if (this.clientType === ClientType.Desktop) {
if (this.captchaSiteKey) {
const content = document.getElementById("content") as HTMLDivElement;
content.setAttribute("style", "width:335px");
}
}
} catch (error) {
this.logService.error(error);
this.handleSubmitError(error);
Expand Down Expand Up @@ -264,12 +249,6 @@ export class LoginComponent implements OnInit, OnDestroy {
* to each if-condition block where necessary to stop code execution.
*/
private async handleAuthResult(authResult: AuthResult): Promise<void> {
if (this.handleCaptchaRequired(authResult)) {
this.captchaSiteKey = authResult.captchaSiteKey;
this.captcha.init(authResult.captchaSiteKey);
return;
}

if (authResult.requiresEncryptionKeyMigration) {
/* Legacy accounts used the master key to encrypt data.
Migration is required but only performed on Web. */
Expand Down Expand Up @@ -359,10 +338,6 @@ export class LoginComponent implements OnInit, OnDestroy {
);
}

protected showCaptcha(): boolean {
return !Utils.isNullOrWhitespace(this.captchaSiteKey);
}

protected async startAuthRequestLogin(): Promise<void> {
this.formGroup.get("masterPassword")?.clearValidators();
this.formGroup.get("masterPassword")?.updateValueAndValidity();
Expand Down Expand Up @@ -482,38 +457,6 @@ export class LoginComponent implements OnInit, OnDestroy {
}
}

private async setupCaptcha(): Promise<void> {
const env = await firstValueFrom(this.environmentService.environment$);
const webVaultUrl = env.getWebVaultUrl();

this.captcha = new CaptchaIFrame(
window,
webVaultUrl,
this.i18nService,
(token: string) => {
this.captchaToken = token;
},
(error: string) => {
this.toastService.showToast({
variant: "error",
title: this.i18nService.t("errorOccurred"),
message: error,
});
},
(info: string) => {
this.toastService.showToast({
variant: "info",
title: this.i18nService.t("info"),
message: info,
});
},
);
}

private handleCaptchaRequired(authResult: AuthResult): boolean {
return !Utils.isNullOrWhitespace(authResult.captchaSiteKey);
}

private async loadEmailSettings(): Promise<void> {
// Try to load the email from memory first
const email = await firstValueFrom(this.loginEmailService.loginEmail$);
Expand Down
1 change: 1 addition & 0 deletions libs/auth/src/common/models/domain/login-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class PasswordLoginCredentials {
constructor(
public email: string,
public masterPassword: string,
// TODO: PM-15162 - captcha is deprecated as part of UI refresh work
public captchaToken?: string,
public twoFactor?: TokenTwoFactorRequest,
) {}
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/auth/captcha-iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { I18nService } from "../platform/abstractions/i18n.service";

import { IFrameComponent } from "./iframe-component";

// TODO: PM-15162 - captcha is deprecated as part of UI refresh work
export class CaptchaIFrame extends IFrameComponent {
constructor(
win: Window,
Expand Down

0 comments on commit 493f81a

Please sign in to comment.