bitwarden-estensione-browser/apps/web/src/app/settings/two-factor-duo.component.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2.4 KiB
TypeScript
Raw Normal View History

import { Component } from "@angular/core";
2018-06-27 21:27:59 +02:00
2022-06-14 17:10:53 +02:00
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification.service";
import { TwoFactorProviderType } from "@bitwarden/common/enums/twoFactorProviderType";
import { UpdateTwoFactorDuoRequest } from "@bitwarden/common/models/request/updateTwoFactorDuoRequest";
import { TwoFactorDuoResponse } from "@bitwarden/common/models/response/twoFactorDuoResponse";
2018-06-27 21:27:59 +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",
})
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>;
constructor(
apiService: ApiService,
i18nService: I18nService,
2021-12-07 20:41:45 +01:00
platformUtilsService: PlatformUtilsService,
logService: LogService,
userVerificationService: UserVerificationService
) {
2021-12-07 20:41:45 +01:00
super(apiService, i18nService, platformUtilsService, logService, userVerificationService);
}
2018-06-27 21:27:59 +02:00
auth(authResponse: any) {
super.auth(authResponse);
this.processResponse(authResponse.response);
2018-06-27 21:27:59 +02:00
}
submit() {
2018-06-27 21:27:59 +02:00
if (this.enabled) {
return super.disable(this.formPromise);
2018-06-27 21:27:59 +02:00
} else {
return this.enable();
2018-06-27 21:27:59 +02:00
}
2021-12-17 15:57:11 +01:00
}
2018-06-27 21:27:59 +02:00
protected async enable() {
const request = await this.buildRequestModel(UpdateTwoFactorDuoRequest);
2018-06-27 21:27:59 +02:00
request.integrationKey = this.ikey;
request.secretKey = this.skey;
request.host = this.host;
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-27 21:27:59 +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;
}
}