2021-10-21 11:10:46 +02:00
|
|
|
import { Component } from "@angular/core";
|
2020-10-14 15:58:36 +02:00
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
2021-10-14 23:58:59 +02:00
|
|
|
import { first } from "rxjs/operators";
|
|
|
|
|
2023-02-06 22:53:37 +01:00
|
|
|
import { TwoFactorComponent as BaseTwoFactorComponent } from "@bitwarden/angular/auth/components/two-factor.component";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
2023-02-06 22:53:37 +01:00
|
|
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
|
|
|
import { LoginService } from "@bitwarden/common/auth/abstractions/login.service";
|
|
|
|
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
|
|
|
import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-provider-type";
|
2023-06-06 22:34:53 +02:00
|
|
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
|
|
|
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.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";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
2023-01-31 22:08:37 +01:00
|
|
|
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
|
2023-08-16 14:26:56 +02:00
|
|
|
import { DialogService } from "@bitwarden/components";
|
2021-03-02 19:31:52 +01:00
|
|
|
|
2023-06-06 22:34:53 +02:00
|
|
|
import { BrowserApi } from "../../platform/browser/browser-api";
|
2023-02-06 22:53:37 +01:00
|
|
|
import { PopupUtilsService } from "../../popup/services/popup-utils.service";
|
2018-12-03 19:47:40 +01:00
|
|
|
|
2018-04-06 21:33:20 +02:00
|
|
|
const BroadcasterSubscriptionId = "TwoFactorComponent";
|
|
|
|
|
2018-04-04 16:08:30 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-two-factor",
|
2018-04-06 17:48:45 +02:00
|
|
|
templateUrl: "two-factor.component.html",
|
2018-04-04 16:08:30 +02:00
|
|
|
})
|
|
|
|
export class TwoFactorComponent extends BaseTwoFactorComponent {
|
2018-04-04 22:53:41 +02:00
|
|
|
showNewWindowMessage = false;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2018-04-04 16:08:30 +02:00
|
|
|
constructor(
|
|
|
|
authService: AuthService,
|
|
|
|
router: Router,
|
|
|
|
i18nService: I18nService,
|
|
|
|
apiService: ApiService,
|
2020-12-09 22:30:03 +01:00
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
private syncService: SyncService,
|
2021-10-21 11:10:46 +02:00
|
|
|
environmentService: EnvironmentService,
|
|
|
|
private broadcasterService: BroadcasterService,
|
2019-07-02 14:26:33 +02:00
|
|
|
private popupUtilsService: PopupUtilsService,
|
|
|
|
stateService: StateService,
|
2021-10-21 11:10:46 +02:00
|
|
|
route: ActivatedRoute,
|
|
|
|
private messagingService: MessagingService,
|
2022-02-08 00:06:37 +01:00
|
|
|
logService: LogService,
|
2022-05-01 23:57:40 +02:00
|
|
|
twoFactorService: TwoFactorService,
|
2022-10-28 20:54:55 +02:00
|
|
|
appIdService: AppIdService,
|
2023-05-02 18:46:03 +02:00
|
|
|
loginService: LoginService,
|
2023-08-16 14:26:56 +02:00
|
|
|
private dialogService: DialogService
|
2021-10-21 11:10:46 +02:00
|
|
|
) {
|
2019-07-02 14:26:33 +02:00
|
|
|
super(
|
|
|
|
authService,
|
|
|
|
router,
|
|
|
|
i18nService,
|
|
|
|
apiService,
|
|
|
|
platformUtilsService,
|
|
|
|
window,
|
|
|
|
environmentService,
|
2021-10-21 11:10:46 +02:00
|
|
|
stateService,
|
|
|
|
route,
|
2022-02-08 00:06:37 +01:00
|
|
|
logService,
|
2022-05-01 23:57:40 +02:00
|
|
|
twoFactorService,
|
2022-10-28 20:54:55 +02:00
|
|
|
appIdService,
|
|
|
|
loginService
|
2021-10-21 11:10:46 +02:00
|
|
|
);
|
2021-09-24 15:34:09 +02:00
|
|
|
super.onSuccessfulLogin = () => {
|
2022-10-28 20:54:55 +02:00
|
|
|
this.loginService.clearValues();
|
2021-09-24 15:34:09 +02:00
|
|
|
return syncService.fullSync(true);
|
2018-04-25 18:08:23 +02:00
|
|
|
};
|
|
|
|
super.successRoute = "/tabs/vault";
|
2023-02-08 23:00:11 +01:00
|
|
|
// FIXME: Chromium 110 has broken WebAuthn support in extensions via an iframe
|
|
|
|
this.webAuthnNewTab = true;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2018-04-04 22:53:41 +02:00
|
|
|
async ngOnInit() {
|
2021-03-17 22:14:26 +01:00
|
|
|
if (this.route.snapshot.paramMap.has("webAuthnResponse")) {
|
|
|
|
// WebAuthn fallback response
|
|
|
|
this.selectedProviderType = TwoFactorProviderType.WebAuthn;
|
|
|
|
this.token = this.route.snapshot.paramMap.get("webAuthnResponse");
|
|
|
|
super.onSuccessfulLogin = async () => {
|
2020-12-09 22:30:03 +01:00
|
|
|
this.syncService.fullSync(true);
|
2021-03-17 22:14:26 +01:00
|
|
|
this.messagingService.send("reloadPopup");
|
|
|
|
window.close();
|
2021-12-21 15:43:35 +01:00
|
|
|
};
|
2021-03-17 22:14:26 +01:00
|
|
|
this.remember = this.route.snapshot.paramMap.get("remember") === "true";
|
|
|
|
await this.doSubmit();
|
2021-12-21 15:43:35 +01:00
|
|
|
return;
|
2018-04-04 16:08:30 +02:00
|
|
|
}
|
|
|
|
|
2018-04-04 22:53:41 +02:00
|
|
|
await super.ngOnInit();
|
|
|
|
if (this.selectedProviderType == null) {
|
2020-12-09 22:30:03 +01:00
|
|
|
return;
|
2018-04-06 21:33:20 +02:00
|
|
|
}
|
2018-04-04 22:53:41 +02:00
|
|
|
|
2018-04-06 21:33:20 +02:00
|
|
|
// WebAuthn prompt appears inside the popup on linux, and requires a larger popup width
|
|
|
|
// than usual to avoid cutting off the dialog.
|
2021-04-06 23:10:22 +02:00
|
|
|
if (this.selectedProviderType === TwoFactorProviderType.WebAuthn && (await this.isLinux())) {
|
|
|
|
document.body.classList.add("linux-webauthn");
|
2018-04-04 22:53:41 +02:00
|
|
|
}
|
|
|
|
|
2021-12-21 15:43:35 +01:00
|
|
|
if (
|
2018-04-04 16:08:30 +02:00
|
|
|
this.selectedProviderType === TwoFactorProviderType.Email &&
|
2018-12-03 19:47:40 +01:00
|
|
|
this.popupUtilsService.inPopup(window)
|
2018-04-04 16:08:30 +02:00
|
|
|
) {
|
2023-05-02 18:46:03 +02:00
|
|
|
const confirmed = await this.dialogService.openSimpleDialog({
|
|
|
|
title: { key: "warning" },
|
|
|
|
content: { key: "popup2faCloseMessage" },
|
2023-08-16 14:26:56 +02:00
|
|
|
type: "warning",
|
2023-05-02 18:46:03 +02:00
|
|
|
});
|
2018-04-04 16:08:30 +02:00
|
|
|
if (confirmed) {
|
|
|
|
this.popupUtilsService.popOut(window);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2018-04-04 16:08:30 +02:00
|
|
|
}
|
2021-04-06 23:10:22 +02:00
|
|
|
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2021-10-14 23:58:59 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe(async (qParams) => {
|
2021-04-06 23:10:22 +02:00
|
|
|
if (qParams.sso === "true") {
|
2020-12-09 22:30:03 +01:00
|
|
|
super.onSuccessfulLogin = () => {
|
2023-05-29 06:37:47 +02:00
|
|
|
// This is not awaited so we don't pause the application while the sync is happening.
|
|
|
|
// This call is executed by the service that lives in the background script so it will continue
|
|
|
|
// the sync even if this tab closes.
|
|
|
|
const syncPromise = this.syncService.fullSync(true);
|
|
|
|
|
|
|
|
// Force sidebars (FF && Opera) to reload while exempting current window
|
|
|
|
// because we are just going to close the current window.
|
|
|
|
BrowserApi.reloadOpenWindows(true);
|
|
|
|
|
|
|
|
// We don't need this window anymore because the intent is for the user to be left
|
|
|
|
// on the web vault screen which tells them to continue in the browser extension (sidebar or popup)
|
|
|
|
BrowserApi.closeBitwardenExtensionTab();
|
|
|
|
|
|
|
|
return syncPromise;
|
2021-12-21 15:43:35 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-06 23:10:22 +02:00
|
|
|
async ngOnDestroy() {
|
2021-04-23 10:45:20 +02:00
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-04-23 10:45:20 +02:00
|
|
|
if (this.selectedProviderType === TwoFactorProviderType.WebAuthn && (await this.isLinux())) {
|
|
|
|
document.body.classList.remove("linux-webauthn");
|
2021-04-06 23:10:22 +02:00
|
|
|
}
|
2018-04-06 21:33:20 +02:00
|
|
|
super.ngOnDestroy();
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
anotherMethod() {
|
2023-05-29 19:55:37 +02:00
|
|
|
const sso = this.route.snapshot.queryParamMap.get("sso") === "true";
|
|
|
|
|
|
|
|
if (sso) {
|
|
|
|
// We must persist this so when the user returns to the 2FA comp, the
|
|
|
|
// proper onSuccessfulLogin logic is executed.
|
|
|
|
this.router.navigate(["2fa-options"], { queryParams: { sso: true } });
|
|
|
|
} else {
|
|
|
|
this.router.navigate(["2fa-options"]);
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2021-04-06 23:10:22 +02:00
|
|
|
async isLinux() {
|
2021-04-23 10:45:20 +02:00
|
|
|
return (await BrowserApi.getPlatformInfo()).os === "linux";
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2018-04-04 16:08:30 +02:00
|
|
|
}
|