2018-06-28 05:55:50 +02:00
|
|
|
import { Component } from '@angular/core';
|
2018-06-27 21:27:59 +02:00
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
2021-10-20 18:30:04 +02:00
|
|
|
import { LogService } from 'jslib-common/abstractions/log.service';
|
2021-06-07 20:13:58 +02:00
|
|
|
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
2018-06-27 21:27:59 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { TwoFactorProviderType } from 'jslib-common/enums/twoFactorProviderType';
|
|
|
|
import { UpdateTwoFactorDuoRequest } from 'jslib-common/models/request/updateTwoFactorDuoRequest';
|
|
|
|
import { TwoFactorDuoResponse } from 'jslib-common/models/response/twoFactorDuoResponse';
|
2018-06-27 21:27:59 +02:00
|
|
|
|
2018-06-28 05:55:50 +02:00
|
|
|
import { TwoFactorBaseComponent } from './two-factor-base.component';
|
|
|
|
|
2018-06-27 21:27:59 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-two-factor-duo',
|
|
|
|
templateUrl: 'two-factor-duo.component.html',
|
|
|
|
})
|
2018-06-28 05:55:50 +02:00
|
|
|
export class TwoFactorDuoComponent extends TwoFactorBaseComponent {
|
2018-07-18 23:10:26 +02:00
|
|
|
type = TwoFactorProviderType.Duo;
|
2018-06-27 21:27:59 +02:00
|
|
|
ikey: string;
|
|
|
|
skey: string;
|
|
|
|
host: string;
|
|
|
|
formPromise: Promise<any>;
|
|
|
|
|
2018-06-28 05:55:50 +02:00
|
|
|
constructor(apiService: ApiService, i18nService: I18nService,
|
2021-10-20 18:30:04 +02:00
|
|
|
toasterService: ToasterService, platformUtilsService: PlatformUtilsService,
|
|
|
|
logService: LogService) {
|
|
|
|
super(apiService, i18nService, toasterService, platformUtilsService, logService);
|
2018-06-28 05:55:50 +02:00
|
|
|
}
|
2018-06-27 21:27:59 +02:00
|
|
|
|
2018-06-28 05:55:50 +02:00
|
|
|
auth(authResponse: any) {
|
|
|
|
super.auth(authResponse);
|
|
|
|
this.processResponse(authResponse.response);
|
2018-06-27 21:27:59 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 05:55:50 +02:00
|
|
|
submit() {
|
2018-06-27 21:27:59 +02:00
|
|
|
if (this.enabled) {
|
2018-06-28 05:55:50 +02:00
|
|
|
return super.disable(this.formPromise);
|
2018-06-27 21:27:59 +02:00
|
|
|
} else {
|
2018-06-28 05:55:50 +02:00
|
|
|
return this.enable();
|
2018-06-27 21:27:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-28 05:55:50 +02:00
|
|
|
protected enable() {
|
2018-06-27 21:27:59 +02:00
|
|
|
const request = new UpdateTwoFactorDuoRequest();
|
|
|
|
request.masterPasswordHash = this.masterPasswordHash;
|
|
|
|
request.integrationKey = this.ikey;
|
|
|
|
request.secretKey = this.skey;
|
|
|
|
request.host = this.host;
|
2018-06-28 05:55:50 +02:00
|
|
|
|
|
|
|
return super.enable(async () => {
|
2018-07-18 23:10:26 +02:00
|
|
|
if (this.organizationId != null) {
|
|
|
|
this.formPromise = this.apiService.putTwoFactorOrganizationDuo(this.organizationId, request);
|
|
|
|
} else {
|
|
|
|
this.formPromise = this.apiService.putTwoFactorDuo(request);
|
|
|
|
}
|
2018-06-27 21:27:59 +02:00
|
|
|
const response = await this.formPromise;
|
|
|
|
await this.processResponse(response);
|
2018-06-28 05:55:50 +02:00
|
|
|
});
|
2018-06-27 21:27:59 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 05:55:50 +02:00
|
|
|
private processResponse(response: TwoFactorDuoResponse) {
|
2018-06-27 21:27:59 +02:00
|
|
|
this.ikey = response.integrationKey;
|
|
|
|
this.skey = response.secretKey;
|
|
|
|
this.host = response.host;
|
|
|
|
this.enabled = response.enabled;
|
|
|
|
}
|
|
|
|
}
|