1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-19 09:43:28 +00:00

Extract 2FA methods to twoFactorService

This commit is contained in:
Thomas Rittson
2021-12-16 14:13:06 +10:00
parent 73eed7fbbc
commit dee5c4bef9
7 changed files with 229 additions and 192 deletions

View File

@@ -21,9 +21,10 @@ import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StateService } from 'jslib-common/abstractions/state.service';
import { TwoFactorProviders } from 'jslib-common/services/auth.service';
import { TwoFactorProviders } from 'jslib-common/services/twoFactor.service';
import * as DuoWebSDK from 'duo_web_sdk';
import { TwoFactorService } from 'jslib-common/abstractions/twoFactor.service';
import { WebAuthnIFrame } from 'jslib-common/misc/webauthn_iframe';
@Directive()
@@ -56,12 +57,13 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
protected i18nService: I18nService, protected apiService: ApiService,
protected platformUtilsService: PlatformUtilsService, protected win: Window,
protected environmentService: EnvironmentService, protected stateService: StateService,
protected route: ActivatedRoute, protected logService: LogService) {
protected route: ActivatedRoute, protected logService: LogService,
protected twoFactorService: TwoFactorService) {
this.webAuthnSupported = this.platformUtilsService.supportsWebAuthn(win);
}
async ngOnInit() {
if (!this.authing || this.authService.twoFactorProvidersData == null) {
if (!this.authing || this.twoFactorService.providers == null) {
this.router.navigate([this.loginRoute]);
return;
}
@@ -92,7 +94,7 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
);
}
this.selectedProviderType = this.authService.getDefaultTwoFactorProvider(this.webAuthnSupported);
this.selectedProviderType = this.twoFactorService.getDefaultTwoFactorProvider(this.webAuthnSupported);
await this.init();
}
@@ -109,7 +111,7 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
this.cleanupWebAuthn();
this.title = (TwoFactorProviders as any)[this.selectedProviderType].name;
const providerData = this.authService.twoFactorProvidersData.get(this.selectedProviderType);
const providerData = this.twoFactorService.providers.get(this.selectedProviderType);
switch (this.selectedProviderType) {
case TwoFactorProviderType.WebAuthn:
if (!this.webAuthnNewTab) {
@@ -137,7 +139,7 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
break;
case TwoFactorProviderType.Email:
this.twoFactorEmail = providerData.Email;
if (this.authService.twoFactorProvidersData.size > 1) {
if (this.twoFactorService.providers.size > 1) {
await this.sendEmail(false);
}
break;
@@ -225,7 +227,7 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
}
authWebAuthn() {
const providerData = this.authService.twoFactorProvidersData.get(this.selectedProviderType);
const providerData = this.twoFactorService.providers.get(this.selectedProviderType);
if (!this.webAuthnSupported || this.webAuthn == null) {
return;

View File

@@ -31,6 +31,7 @@ import { StateMigrationService } from 'jslib-common/services/stateMigration.serv
import { SyncService } from 'jslib-common/services/sync.service';
import { TokenService } from 'jslib-common/services/token.service';
import { TotpService } from 'jslib-common/services/totp.service';
import { TwoFactorService } from 'jslib-common/services/twoFactor.service';
import { UserVerificationService } from 'jslib-common/services/userVerification.service';
import { VaultTimeoutService } from 'jslib-common/services/vaultTimeout.service';
import { WebCryptoFunctionService } from 'jslib-common/services/webCryptoFunction.service';
@@ -71,6 +72,7 @@ import { StorageService as StorageServiceAbstraction } from 'jslib-common/abstra
import { SyncService as SyncServiceAbstraction } from 'jslib-common/abstractions/sync.service';
import { TokenService as TokenServiceAbstraction } from 'jslib-common/abstractions/token.service';
import { TotpService as TotpServiceAbstraction } from 'jslib-common/abstractions/totp.service';
import { TwoFactorService as TwoFactorServiceAbstraction } from 'jslib-common/abstractions/twoFactor.service';
import { UserVerificationService as UserVerificationServiceAbstraction } from 'jslib-common/abstractions/userVerification.service';
import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from 'jslib-common/abstractions/vaultTimeout.service';
@@ -114,14 +116,13 @@ import { ValidationService } from './validation.service';
ApiServiceAbstraction,
TokenServiceAbstraction,
AppIdServiceAbstraction,
I18nServiceAbstraction,
PlatformUtilsServiceAbstraction,
MessagingServiceAbstraction,
VaultTimeoutServiceAbstraction,
LogService,
CryptoFunctionServiceAbstraction,
KeyConnectorServiceAbstraction,
EnvironmentServiceAbstraction,
TwoFactorServiceAbstraction,
StateServiceAbstraction,
],
},
@@ -474,6 +475,14 @@ import { ValidationService } from './validation.service';
StateServiceAbstraction,
],
},
{
provide: TwoFactorServiceAbstraction,
useClass: TwoFactorService,
deps: [
I18nServiceAbstraction,
PlatformUtilsServiceAbstraction,
],
},
],
})
export class JslibServicesModule {