2022-09-14 22:05:21 +00:00
|
|
|
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
2023-02-22 12:19:01 +00:00
|
|
|
import { dateTimeLocal } from "@goauthentik/common/utils";
|
2022-09-14 22:05:21 +00:00
|
|
|
import { Form } from "@goauthentik/elements/forms/Form";
|
|
|
|
import "@goauthentik/elements/forms/HorizontalFormElement";
|
|
|
|
import { ModalForm } from "@goauthentik/elements/forms/ModalForm";
|
2022-06-25 15:44:17 +00:00
|
|
|
|
2021-08-24 18:13:05 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-10-28 07:48:51 +00:00
|
|
|
import { TemplateResult, html } from "lit";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { customElement, property } from "lit/decorators.js";
|
|
|
|
import { ifDefined } from "lit/directives/if-defined.js";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
|
|
|
import { CoreApi, UserServiceAccountRequest, UserServiceAccountResponse } from "@goauthentik/api";
|
|
|
|
|
2021-08-24 18:13:05 +00:00
|
|
|
@customElement("ak-user-service-account")
|
|
|
|
export class ServiceAccountForm extends Form<UserServiceAccountRequest> {
|
|
|
|
@property({ attribute: false })
|
|
|
|
result?: UserServiceAccountResponse;
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
|
|
|
return t`Successfully created user.`;
|
|
|
|
}
|
|
|
|
|
2023-01-02 15:13:07 +00:00
|
|
|
send = async (data: UserServiceAccountRequest): Promise<UserServiceAccountResponse> => {
|
|
|
|
const result = await new CoreApi(DEFAULT_CONFIG).coreUsersServiceAccountCreate({
|
|
|
|
userServiceAccountRequest: data,
|
|
|
|
});
|
|
|
|
this.result = result;
|
|
|
|
(this.parentElement as ModalForm).showSubmitButton = false;
|
|
|
|
return result;
|
2021-08-24 18:13:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
resetForm(): void {
|
|
|
|
super.resetForm();
|
|
|
|
this.result = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderRequestForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<ak-form-element-horizontal label=${t`Username`} ?required=${true} name="name">
|
|
|
|
<input type="text" value="" class="pf-c-form-control" required />
|
|
|
|
<p class="pf-c-form__helper-text">
|
2022-06-10 20:59:59 +00:00
|
|
|
${t`User's primary identifier. 150 characters or fewer.`}
|
2021-08-24 18:13:05 +00:00
|
|
|
</p>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal name="createGroup">
|
2023-01-11 12:37:49 +00:00
|
|
|
<label class="pf-c-switch">
|
|
|
|
<input class="pf-c-switch__input" type="checkbox" ?checked=${true} />
|
|
|
|
<span class="pf-c-switch__toggle">
|
|
|
|
<span class="pf-c-switch__toggle-icon">
|
|
|
|
<i class="fas fa-check" aria-hidden="true"></i>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
<span class="pf-c-switch__label">${t`Create group`}</span>
|
|
|
|
</label>
|
2021-08-24 18:13:05 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Enabling this toggle will create a group named after the user, with the user as member.`}
|
|
|
|
</p>
|
|
|
|
</ak-form-element-horizontal>
|
2023-02-22 12:19:01 +00:00
|
|
|
<ak-form-element-horizontal name="expiring">
|
|
|
|
<label class="pf-c-switch">
|
|
|
|
<input class="pf-c-switch__input" type="checkbox" ?checked=${true} />
|
|
|
|
<span class="pf-c-switch__toggle">
|
|
|
|
<span class="pf-c-switch__toggle-icon">
|
|
|
|
<i class="fas fa-check" aria-hidden="true"></i>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
<span class="pf-c-switch__label">${t`Expiring`}</span>
|
|
|
|
</label>
|
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`If this is selected, the token will expire. Upon expiration, the token will be rotated.`}
|
|
|
|
</p>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal label=${t`Expires on`} name="expires">
|
|
|
|
<input
|
|
|
|
type="datetime-local"
|
|
|
|
data-type="datetime-local"
|
|
|
|
value="${dateTimeLocal(new Date(Date.now() + 1000 * 60 ** 2 * 24 * 360))}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
/>
|
|
|
|
</ak-form-element-horizontal>
|
2021-08-24 18:13:05 +00:00
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderResponseForm(): TemplateResult {
|
|
|
|
return html`<p>
|
|
|
|
${t`Use the username and password below to authenticate. The password can be retrieved later on the Tokens page.`}
|
|
|
|
</p>
|
|
|
|
<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<ak-form-element-horizontal label=${t`Username`}>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
readonly
|
|
|
|
value=${ifDefined(this.result?.username)}
|
|
|
|
class="pf-c-form-control"
|
|
|
|
/>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal label=${t`Password`}>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
readonly
|
|
|
|
value=${ifDefined(this.result?.token)}
|
|
|
|
class="pf-c-form-control"
|
|
|
|
/>
|
2021-09-16 07:57:34 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Valid for 360 days, after which the password will automatically rotate. You can copy the password from the Token List.`}
|
|
|
|
</p>
|
2021-08-24 18:13:05 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
if (this.result) {
|
|
|
|
return this.renderResponseForm();
|
|
|
|
}
|
|
|
|
return this.renderRequestForm();
|
|
|
|
}
|
|
|
|
}
|