diff --git a/src/abstractions/auth.service.ts b/src/abstractions/auth.service.ts index 4b2b2434d0..7b721433c0 100644 --- a/src/abstractions/auth.service.ts +++ b/src/abstractions/auth.service.ts @@ -11,6 +11,9 @@ export abstract class AuthService { logIn: (email: string, masterPassword: string) => Promise; logInTwoFactor: (twoFactorProvider: TwoFactorProviderType, twoFactorToken: string, remember?: boolean) => Promise; + logInComplete: (email: string, masterPassword: string, twoFactorProvider: TwoFactorProviderType, + twoFactorToken: string, remember?: boolean) => Promise; logOut: (callback: Function) => void; + getSupportedTwoFactorProviders: (win: Window) => any[]; getDefaultTwoFactorProvider: (u2fSupported: boolean) => TwoFactorProviderType; } diff --git a/src/angular/components/two-factor-options.component.ts b/src/angular/components/two-factor-options.component.ts index e28fdef321..998ad76743 100644 --- a/src/angular/components/two-factor-options.component.ts +++ b/src/angular/components/two-factor-options.component.ts @@ -29,30 +29,7 @@ export class TwoFactorOptionsComponent implements OnInit { protected win: Window) { } ngOnInit() { - if (this.authService.twoFactorProviders.has(TwoFactorProviderType.OrganizationDuo)) { - this.providers.push(TwoFactorProviders[TwoFactorProviderType.OrganizationDuo]); - } - - if (this.authService.twoFactorProviders.has(TwoFactorProviderType.Authenticator)) { - this.providers.push(TwoFactorProviders[TwoFactorProviderType.Authenticator]); - } - - if (this.authService.twoFactorProviders.has(TwoFactorProviderType.Yubikey)) { - this.providers.push(TwoFactorProviders[TwoFactorProviderType.Yubikey]); - } - - if (this.authService.twoFactorProviders.has(TwoFactorProviderType.Duo)) { - this.providers.push(TwoFactorProviders[TwoFactorProviderType.Duo]); - } - - if (this.authService.twoFactorProviders.has(TwoFactorProviderType.U2f) && - this.platformUtilsService.supportsU2f(this.win)) { - this.providers.push(TwoFactorProviders[TwoFactorProviderType.U2f]); - } - - if (this.authService.twoFactorProviders.has(TwoFactorProviderType.Email)) { - this.providers.push(TwoFactorProviders[TwoFactorProviderType.Email]); - } + this.providers = this.authService.getSupportedTwoFactorProviders(this.win); } choose(p: any) { diff --git a/src/services/auth.service.ts b/src/services/auth.service.ts index 07ba8a0c32..318dceebf8 100644 --- a/src/services/auth.service.ts +++ b/src/services/auth.service.ts @@ -37,6 +37,12 @@ export const TwoFactorProviders = { description: null as string, priority: 2, }, + [TwoFactorProviderType.OrganizationDuo]: { + type: TwoFactorProviderType.OrganizationDuo, + name: 'Duo (Organization)', + description: null as string, + priority: 10, + }, [TwoFactorProviderType.U2f]: { type: TwoFactorProviderType.U2f, name: null as string, @@ -49,12 +55,6 @@ export const TwoFactorProviders = { description: null as string, priority: 0, }, - [TwoFactorProviderType.OrganizationDuo]: { - type: TwoFactorProviderType.OrganizationDuo, - name: 'Duo (Organization)', - description: null as string, - priority: 10, - }, }; export class AuthService { @@ -107,11 +107,53 @@ export class AuthService { twoFactorToken, remember); } + async logInComplete(email: string, masterPassword: string, twoFactorProvider: TwoFactorProviderType, + twoFactorToken: string, remember?: boolean): Promise { + this.selectedTwoFactorProviderType = null; + email = email.toLowerCase(); + const key = await this.cryptoService.makeKey(masterPassword, email); + const hashedPassword = await this.cryptoService.hashPassword(masterPassword, key); + return await this.logInHelper(email, hashedPassword, key, twoFactorProvider, twoFactorToken, remember); + } + logOut(callback: Function) { callback(); this.messagingService.send('loggedOut'); } + getSupportedTwoFactorProviders(win: Window): any[] { + const providers: any[] = []; + if (this.twoFactorProviders == null) { + return providers; + } + + if (this.twoFactorProviders.has(TwoFactorProviderType.OrganizationDuo)) { + providers.push(TwoFactorProviders[TwoFactorProviderType.OrganizationDuo]); + } + + if (this.twoFactorProviders.has(TwoFactorProviderType.Authenticator)) { + providers.push(TwoFactorProviders[TwoFactorProviderType.Authenticator]); + } + + if (this.twoFactorProviders.has(TwoFactorProviderType.Yubikey)) { + providers.push(TwoFactorProviders[TwoFactorProviderType.Yubikey]); + } + + if (this.twoFactorProviders.has(TwoFactorProviderType.Duo)) { + providers.push(TwoFactorProviders[TwoFactorProviderType.Duo]); + } + + if (this.twoFactorProviders.has(TwoFactorProviderType.U2f) && this.platformUtilsService.supportsU2f(win)) { + providers.push(TwoFactorProviders[TwoFactorProviderType.U2f]); + } + + if (this.twoFactorProviders.has(TwoFactorProviderType.Email)) { + providers.push(TwoFactorProviders[TwoFactorProviderType.Email]); + } + + return providers; + } + getDefaultTwoFactorProvider(u2fSupported: boolean): TwoFactorProviderType { if (this.twoFactorProviders == null) { return null; diff --git a/src/services/crypto.service.ts b/src/services/crypto.service.ts index 8ff31b0c6d..5df0f61911 100644 --- a/src/services/crypto.service.ts +++ b/src/services/crypto.service.ts @@ -248,8 +248,9 @@ export class CryptoService implements CryptoServiceAbstraction { } async hashPassword(password: string, key: SymmetricCryptoKey): Promise { - const storedKey = await this.getKey(); - key = key || storedKey; + if (key == null) { + key = await this.getKey(); + } if (password == null || key == null) { throw new Error('Invalid parameters.'); }