2fa adjustments in auth services

This commit is contained in:
Kyle Spearrin 2018-05-15 21:11:20 -04:00
parent f173001a41
commit 7112911cb8
4 changed files with 55 additions and 32 deletions

View File

@ -11,6 +11,9 @@ export abstract class AuthService {
logIn: (email: string, masterPassword: string) => Promise<AuthResult>;
logInTwoFactor: (twoFactorProvider: TwoFactorProviderType, twoFactorToken: string,
remember?: boolean) => Promise<AuthResult>;
logInComplete: (email: string, masterPassword: string, twoFactorProvider: TwoFactorProviderType,
twoFactorToken: string, remember?: boolean) => Promise<AuthResult>;
logOut: (callback: Function) => void;
getSupportedTwoFactorProviders: (win: Window) => any[];
getDefaultTwoFactorProvider: (u2fSupported: boolean) => TwoFactorProviderType;
}

View File

@ -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) {

View File

@ -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<AuthResult> {
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;

View File

@ -248,8 +248,9 @@ export class CryptoService implements CryptoServiceAbstraction {
}
async hashPassword(password: string, key: SymmetricCryptoKey): Promise<string> {
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.');
}