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";
|
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { TwoFactorComponent as BaseTwoFactorComponent } from "@bitwarden/angular/components/two-factor.component";
|
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { AppIdService } from "@bitwarden/common/abstractions/appId.service";
|
|
|
|
import { AuthService } from "@bitwarden/common/abstractions/auth.service";
|
|
|
|
import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service";
|
|
|
|
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
|
|
|
import { SyncService } from "@bitwarden/common/abstractions/sync.service";
|
|
|
|
import { TwoFactorService } from "@bitwarden/common/abstractions/twoFactor.service";
|
|
|
|
import { TwoFactorProviderType } from "@bitwarden/common/enums/twoFactorProviderType";
|
2021-03-02 19:31:52 +01:00
|
|
|
|
2020-12-09 22:30:03 +01:00
|
|
|
import { BrowserApi } from "../../browser/browserApi";
|
2022-02-24 18:14:04 +01:00
|
|
|
import { PopupUtilsService } from "../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,
|
|
|
|
appIdService: AppIdService
|
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,
|
|
|
|
appIdService
|
2021-10-21 11:10:46 +02:00
|
|
|
);
|
2021-09-24 15:34:09 +02:00
|
|
|
super.onSuccessfulLogin = () => {
|
|
|
|
return syncService.fullSync(true);
|
2018-04-25 18:08:23 +02:00
|
|
|
};
|
|
|
|
super.successRoute = "/tabs/vault";
|
2021-03-17 22:14:26 +01:00
|
|
|
this.webAuthnNewTab =
|
|
|
|
this.platformUtilsService.isFirefox() || this.platformUtilsService.isSafari();
|
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
|
|
|
) {
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(
|
|
|
|
this.i18nService.t("popup2faCloseMessage"),
|
2021-12-21 15:43:35 +01:00
|
|
|
null,
|
2018-12-03 19:47:40 +01:00
|
|
|
this.i18nService.t("yes"),
|
|
|
|
this.i18nService.t("no")
|
2021-12-21 15:43:35 +01: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 = () => {
|
|
|
|
BrowserApi.reloadOpenWindows();
|
2021-04-06 23:10:22 +02:00
|
|
|
const thisWindow = window.open("", "_self");
|
2020-12-09 22:30:03 +01:00
|
|
|
thisWindow.close();
|
|
|
|
return this.syncService.fullSync(true);
|
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() {
|
2018-04-04 16:08:30 +02:00
|
|
|
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
|
|
|
}
|