2021-04-26 21:25:03 +00:00
|
|
|
import { FlowDesignationEnum, FlowsApi, ProvidersApi, LDAPProvider, CoreApi } from "authentik-api";
|
2021-04-26 10:03:44 +00:00
|
|
|
import { t } from "@lingui/macro";
|
|
|
|
import { customElement, property } from "lit-element";
|
|
|
|
import { html, TemplateResult } from "lit-html";
|
|
|
|
import { DEFAULT_CONFIG } from "../../../api/Config";
|
2021-05-11 09:48:34 +00:00
|
|
|
import { ModelForm } from "../../../elements/forms/ModelForm";
|
2021-04-26 10:03:44 +00:00
|
|
|
import { until } from "lit-html/directives/until";
|
|
|
|
import { ifDefined } from "lit-html/directives/if-defined";
|
|
|
|
import "../../../elements/forms/HorizontalFormElement";
|
|
|
|
import "../../../elements/forms/FormGroup";
|
|
|
|
import { first } from "../../../utils";
|
|
|
|
|
|
|
|
@customElement("ak-provider-ldap-form")
|
2021-05-11 09:48:34 +00:00
|
|
|
export class LDAPProviderFormPage extends ModelForm<LDAPProvider, number> {
|
2021-04-26 10:03:44 +00:00
|
|
|
|
2021-05-11 09:48:34 +00:00
|
|
|
loadInstance(pk: number): Promise<LDAPProvider> {
|
|
|
|
return new ProvidersApi(DEFAULT_CONFIG).providersLdapRead({
|
|
|
|
id: pk,
|
2021-04-26 10:03:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-05-11 09:48:34 +00:00
|
|
|
if (this.instance) {
|
2021-04-26 10:03:44 +00:00
|
|
|
return t`Successfully updated provider.`;
|
|
|
|
} else {
|
|
|
|
return t`Successfully created provider.`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: LDAPProvider): Promise<LDAPProvider> => {
|
2021-05-11 09:48:34 +00:00
|
|
|
if (this.instance) {
|
2021-04-26 10:03:44 +00:00
|
|
|
return new ProvidersApi(DEFAULT_CONFIG).providersLdapUpdate({
|
2021-05-11 09:48:34 +00:00
|
|
|
id: this.instance.pk || 0,
|
2021-04-26 10:03:44 +00:00
|
|
|
data: data
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new ProvidersApi(DEFAULT_CONFIG).providersLdapCreate({
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<ak-form-element-horizontal
|
|
|
|
label=${t`Name`}
|
|
|
|
?required=${true}
|
|
|
|
name="name">
|
2021-05-11 09:48:34 +00:00
|
|
|
<input type="text" value="${ifDefined(this.instance?.name)}" class="pf-c-form-control" required>
|
2021-04-26 10:03:44 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
|
|
|
label=${t`Bind flow`}
|
|
|
|
?required=${true}
|
2021-04-26 12:46:29 +00:00
|
|
|
name="authorizationFlow">
|
2021-04-26 10:03:44 +00:00
|
|
|
<select class="pf-c-form-control">
|
|
|
|
${until(new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({
|
|
|
|
ordering: "pk",
|
|
|
|
designation: FlowDesignationEnum.Authentication,
|
|
|
|
}).then(flows => {
|
|
|
|
return flows.results.map(flow => {
|
2021-05-11 09:48:34 +00:00
|
|
|
return html`<option value=${ifDefined(flow.pk)} ?selected=${this.instance?.authorizationFlow === flow.pk}>${flow.name} (${flow.slug})</option>`;
|
2021-04-26 10:03:44 +00:00
|
|
|
});
|
|
|
|
}), html`<option>${t`Loading...`}</option>`)}
|
|
|
|
</select>
|
|
|
|
<p class="pf-c-form__helper-text">${t`Flow used for users to authenticate. Currently only identification and password stages are supported.`}</p>
|
|
|
|
</ak-form-element-horizontal>
|
2021-04-26 21:25:03 +00:00
|
|
|
<ak-form-element-horizontal
|
|
|
|
label=${t`Group`}
|
|
|
|
name="searchGroup">
|
|
|
|
<select class="pf-c-form-control">
|
2021-05-11 09:48:34 +00:00
|
|
|
<option value="" ?selected=${this.instance?.searchGroup === undefined}>---------</option>
|
2021-04-26 21:25:03 +00:00
|
|
|
${until(new CoreApi(DEFAULT_CONFIG).coreGroupsList({}).then(groups => {
|
|
|
|
return groups.results.map(group => {
|
2021-05-11 09:48:34 +00:00
|
|
|
return html`<option value=${ifDefined(group.pk)} ?selected=${this.instance?.searchGroup === group.pk}>${group.name}</option>`;
|
2021-04-26 21:25:03 +00:00
|
|
|
});
|
|
|
|
}), html`<option>${t`Loading...`}</option>`)}
|
|
|
|
</select>
|
|
|
|
<p class="pf-c-form__helper-text">${t`Users in the selected group can do search queries.`}</p>
|
|
|
|
</ak-form-element-horizontal>
|
2021-04-26 10:03:44 +00:00
|
|
|
|
|
|
|
<ak-form-group .expanded=${true}>
|
|
|
|
<span slot="header">
|
|
|
|
${t`Protocol settings`}
|
|
|
|
</span>
|
|
|
|
<div slot="body" class="pf-c-form">
|
|
|
|
<ak-form-element-horizontal
|
|
|
|
label=${t`Base DN`}
|
|
|
|
?required=${true}
|
|
|
|
name="baseDn">
|
2021-05-11 09:48:34 +00:00
|
|
|
<input type="text" value="${first(this.instance?.baseDn, "DC=ldap,DC=goauthentik,DC=io")}" class="pf-c-form-control" required>
|
2021-04-26 10:03:44 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`LDAP DN under which bind requests and search requests can be made.`}</p>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</div>
|
|
|
|
</ak-form-group>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|