2021-05-16 16:46:04 +00:00
|
|
|
import { FlowDesignationEnum, FlowsApi, FlowsInstancesListDesignationEnum, ProvidersApi, SAMLProvider } from "authentik-api";
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-04-01 17:28:12 +00:00
|
|
|
import { customElement } from "lit-element";
|
|
|
|
import { html, TemplateResult } from "lit-html";
|
|
|
|
import { ifDefined } from "lit-html/directives/if-defined";
|
|
|
|
import { until } from "lit-html/directives/until";
|
|
|
|
import { DEFAULT_CONFIG } from "../../../api/Config";
|
|
|
|
import { Form } from "../../../elements/forms/Form";
|
|
|
|
import "../../../elements/forms/HorizontalFormElement";
|
|
|
|
|
|
|
|
@customElement("ak-provider-saml-import-form")
|
|
|
|
export class SAMLProviderImportForm extends Form<SAMLProvider> {
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully imported provider.`;
|
2021-04-01 17:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line
|
|
|
|
send = (data: SAMLProvider): Promise<void> => {
|
|
|
|
const file = this.getFormFile();
|
|
|
|
if (!file) {
|
|
|
|
throw new Error("No form data");
|
|
|
|
}
|
|
|
|
return new ProvidersApi(DEFAULT_CONFIG).providersSamlImportMetadata({
|
|
|
|
file: file,
|
|
|
|
name: data.name,
|
|
|
|
authorizationFlow: data.authorizationFlow,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Name`}
|
2021-04-01 17:28:12 +00:00
|
|
|
?required=${true}
|
|
|
|
name="name">
|
|
|
|
<input type="text" class="pf-c-form-control" required>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Authorization flow`}
|
2021-04-01 17:28:12 +00:00
|
|
|
?required=${true}
|
|
|
|
name="authorizationFlow">
|
|
|
|
<select class="pf-c-form-control">
|
|
|
|
${until(new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({
|
|
|
|
ordering: "pk",
|
2021-05-16 16:46:04 +00:00
|
|
|
designation: FlowsInstancesListDesignationEnum.Authorization,
|
2021-04-01 17:28:12 +00:00
|
|
|
}).then(flows => {
|
|
|
|
return flows.results.map(flow => {
|
2021-04-02 10:48:09 +00:00
|
|
|
return html`<option value=${ifDefined(flow.pk)}>${flow.name} (${flow.slug})</option>`;
|
2021-04-01 17:28:12 +00:00
|
|
|
});
|
2021-04-03 22:24:06 +00:00
|
|
|
}), html`<option>${t`Loading...`}</option>`)}
|
2021-04-01 17:28:12 +00:00
|
|
|
</select>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Flow used when authorizing this provider.`}</p>
|
2021-04-01 17:28:12 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Metadata`}
|
2021-04-01 17:28:12 +00:00
|
|
|
name="flow">
|
|
|
|
<input type="file" value="" class="pf-c-form-control">
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|