mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-09 05:57:40 +02:00
816bcf4f39
* refactor login strategies into own service * create login service factory * replaces instances of authService with loginStrategyService * replace more instances of authService * move logout back to auth service * add browser dependencies * fix desktop dependencies * fix cli dependencies * fix lint and test files * fix anonymous hub deps * fix webauthn-login service deps * add loginstrategyservice to bg * move login strategy service and models to auth folder * revert changes to tsconfig * use alias for imports * fix path --------- Co-authored-by: rr-bw <102181210+rr-bw@users.noreply.github.com>
132 lines
5.0 KiB
TypeScript
132 lines
5.0 KiB
TypeScript
import { Component, Inject, OnDestroy, ViewChild, ViewContainerRef } from "@angular/core";
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
|
|
|
import { TwoFactorComponent as BaseTwoFactorComponent } from "@bitwarden/angular/auth/components/two-factor.component";
|
|
import { WINDOW } from "@bitwarden/angular/services/injection-tokens";
|
|
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
|
import { LoginStrategyServiceAbstraction } from "@bitwarden/auth/common";
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.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";
|
|
import { AuthResult } from "@bitwarden/common/auth/models/domain/auth-result";
|
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
|
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
|
|
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 { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
|
|
|
import { TwoFactorOptionsComponent } from "./two-factor-options.component";
|
|
|
|
@Component({
|
|
selector: "app-two-factor",
|
|
templateUrl: "two-factor.component.html",
|
|
})
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
|
export class TwoFactorComponent extends BaseTwoFactorComponent implements OnDestroy {
|
|
@ViewChild("twoFactorOptions", { read: ViewContainerRef, static: true })
|
|
twoFactorOptionsModal: ViewContainerRef;
|
|
|
|
constructor(
|
|
loginStrategyService: LoginStrategyServiceAbstraction,
|
|
router: Router,
|
|
i18nService: I18nService,
|
|
apiService: ApiService,
|
|
platformUtilsService: PlatformUtilsService,
|
|
stateService: StateService,
|
|
environmentService: EnvironmentService,
|
|
private modalService: ModalService,
|
|
route: ActivatedRoute,
|
|
logService: LogService,
|
|
twoFactorService: TwoFactorService,
|
|
appIdService: AppIdService,
|
|
loginService: LoginService,
|
|
configService: ConfigServiceAbstraction,
|
|
@Inject(WINDOW) protected win: Window,
|
|
) {
|
|
super(
|
|
loginStrategyService,
|
|
router,
|
|
i18nService,
|
|
apiService,
|
|
platformUtilsService,
|
|
win,
|
|
environmentService,
|
|
stateService,
|
|
route,
|
|
logService,
|
|
twoFactorService,
|
|
appIdService,
|
|
loginService,
|
|
configService,
|
|
);
|
|
this.onSuccessfulLoginNavigate = this.goAfterLogIn;
|
|
}
|
|
|
|
async anotherMethod() {
|
|
const [modal] = await this.modalService.openViewRef(
|
|
TwoFactorOptionsComponent,
|
|
this.twoFactorOptionsModal,
|
|
(comp) => {
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
|
comp.onProviderSelected.subscribe(async (provider: TwoFactorProviderType) => {
|
|
modal.close();
|
|
this.selectedProviderType = provider;
|
|
await this.init();
|
|
});
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
|
comp.onRecoverSelected.subscribe(() => {
|
|
modal.close();
|
|
});
|
|
},
|
|
);
|
|
}
|
|
|
|
protected override handleMigrateEncryptionKey(result: AuthResult): boolean {
|
|
if (!result.requiresEncryptionKeyMigration) {
|
|
return false;
|
|
}
|
|
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
this.router.navigate(["migrate-legacy-encryption"]);
|
|
return true;
|
|
}
|
|
|
|
goAfterLogIn = async () => {
|
|
this.loginService.clearValues();
|
|
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
this.router.navigate([this.successRoute], {
|
|
queryParams: {
|
|
identifier: this.orgIdentifier,
|
|
},
|
|
});
|
|
};
|
|
|
|
private duoResultChannel: BroadcastChannel;
|
|
|
|
protected override setupDuoResultListener() {
|
|
if (!this.duoResultChannel) {
|
|
this.duoResultChannel = new BroadcastChannel("duoResult");
|
|
this.duoResultChannel.addEventListener("message", this.handleDuoResultMessage);
|
|
}
|
|
}
|
|
|
|
private handleDuoResultMessage = async (msg: { data: { code: string } }) => {
|
|
this.token = msg.data.code;
|
|
await this.submit();
|
|
};
|
|
|
|
async ngOnDestroy() {
|
|
super.ngOnDestroy();
|
|
|
|
if (this.duoResultChannel) {
|
|
// clean up duo listener if it was initialized.
|
|
this.duoResultChannel.removeEventListener("message", this.handleDuoResultMessage);
|
|
this.duoResultChannel.close();
|
|
}
|
|
}
|
|
}
|