import { AKResponse } from "@goauthentik/web/api/Client"; import { AndNext, DEFAULT_CONFIG } from "@goauthentik/web/api/Config"; import "@goauthentik/web/elements/buttons/Dropdown"; import "@goauthentik/web/elements/buttons/ModalButton"; import "@goauthentik/web/elements/buttons/TokenCopyButton"; import "@goauthentik/web/elements/forms/DeleteBulkForm"; import "@goauthentik/web/elements/forms/ModalForm"; import { Table, TableColumn } from "@goauthentik/web/elements/table/Table"; import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { until } from "lit/directives/until.js"; import { AuthenticatorsApi, Device, UserSetting } from "@goauthentik/api"; import "./MFADeviceForm"; export function stageToAuthenticatorName(stage: UserSetting): string { switch (stage.component) { case "ak-user-settings-authenticator-duo": return t`Duo authenticator`; case "ak-user-settings-authenticator-sms": return t`SMS authenticator`; case "ak-user-settings-authenticator-static": return t`Static authenticator`; case "ak-user-settings-authenticator-totp": return t`TOTP authenticator`; case "ak-user-settings-authenticator-webauthn": return t`Security key authenticator`; } return `Invalid stage component ${stage.component}`; } @customElement("ak-user-settings-mfa") export class MFADevicesPage extends Table { @property({ attribute: false }) userSettings?: Promise; checkbox = true; // eslint-disable-next-line @typescript-eslint/no-unused-vars async apiEndpoint(page: number): Promise> { const devices = await new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsAllList(); return { pagination: { current: 0, count: devices.length, totalPages: 1, startIndex: 1, endIndex: devices.length, }, results: devices, }; } columns(): TableColumn[] { return [new TableColumn(t`Name`), new TableColumn(t`Type`), new TableColumn("")]; } renderToolbar(): TemplateResult { return html` ${super.renderToolbar()}`; } async deleteWrapper(device: Device) { switch (device.type) { case "authentik_stages_authenticator_duo.DuoDevice": return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsDuoDestroy({ id: device.pk, }); case "authentik_stages_authenticator_sms.SMSDevice": return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsSmsDestroy({ id: device.pk, }); case "otp_totp.TOTPDevice": return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpDestroy({ id: device.pk, }); case "otp_static.StaticDevice": return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticDestroy({ id: device.pk, }); case "authentik_stages_authenticator_webauthn.WebAuthnDevice": return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsWebauthnDestroy({ id: device.pk, }); default: break; } } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; return html` { return this.deleteWrapper(item); }} > `; } deviceTypeName(device: Device): string { switch (device.type) { case "otp_static.StaticDevice": return t`Static tokens`; case "otp_totp.TOTPDevice": return t`TOTP Device`; default: return device.verboseName; } } row(item: Device): TemplateResult[] { return [ html`${item.name}`, html`${this.deviceTypeName(item)}`, html` ${t`Update`} ${t`Update Device`} `, ]; } }