import { t } from "@lingui/macro"; import { html, TemplateResult } from "lit"; import { customElement } from "lit/decorators"; import { until } from "lit/directives/until"; import { CoreApi, IntentEnum, Token } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../api/Config"; import "../../elements/forms/FormGroup"; import "../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../elements/forms/ModelForm"; import { dateTimeLocal, first } from "../../utils"; @customElement("ak-token-form") export class TokenForm extends ModelForm { loadInstance(pk: string): Promise { return new CoreApi(DEFAULT_CONFIG).coreTokensRetrieve({ identifier: pk, }); } getSuccessMessage(): string { if (this.instance) { return t`Successfully updated token.`; } else { return t`Successfully created token.`; } } send = (data: Token): Promise => { if (this.instance?.identifier) { return new CoreApi(DEFAULT_CONFIG).coreTokensUpdate({ identifier: this.instance.identifier, tokenRequest: data, }); } else { return new CoreApi(DEFAULT_CONFIG).coreTokensCreate({ tokenRequest: data, }); } }; renderForm(): TemplateResult { return html` ${t`Unique identifier the token is referenced by.`} ${until( new CoreApi(DEFAULT_CONFIG) .coreUsersList({ ordering: "username", }) .then((users) => { return users.results.map((user) => { return html` ${user.username} `; }); }), html`${t`Loading...`}`, )} ${t`API Token (can be used to access the API programmatically)`} ${t`App password (can be used to login using a flow executor)`} ${t`Expiring?`} ${t`If this is selected, the token will expire. Upon expiration, the token will be rotated.`} `; } }
${t`Unique identifier the token is referenced by.`}
${t`If this is selected, the token will expire. Upon expiration, the token will be rotated.`}