import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement } from "lit/decorators"; import { ifDefined } from "lit/directives/if-defined"; import { AuthenticatorsApi, Device } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../../api/Config"; import "../../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-user-mfa-form") export class MFADeviceForm extends ModelForm { loadInstance(pk: number): Promise { return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsAllList().then((devices) => { return devices.filter((device) => device.pk === pk)[0]; }); } getSuccessMessage(): string { return t`Successfully updated device.`; } send = async (device: Device): Promise => { switch (this.instance?.type) { case "authentik_stages_authenticator_duo.DuoDevice": await new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsDuoUpdate({ id: this.instance?.pk, duoDeviceRequest: device, }); case "authentik_stages_authenticator_sms.SMSDevice": await new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsSmsUpdate({ id: this.instance?.pk, sMSDeviceRequest: device, }); case "otp_totp.TOTPDevice": await new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpUpdate({ id: this.instance?.pk, tOTPDeviceRequest: device, }); case "otp_static.StaticDevice": await new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticUpdate({ id: this.instance?.pk, staticDeviceRequest: device, }); case "authentik_stages_authenticator_webauthn.WebAuthnDevice": await new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsWebauthnUpdate({ id: this.instance?.pk, webAuthnDeviceRequest: device, }); default: break; } return device; }; renderForm(): TemplateResult { return html`
`; } }