2021-08-03 15:52:21 +00:00
|
|
|
import {
|
|
|
|
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 { 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");
|
|
|
|
}
|
2021-05-16 16:52:27 +00:00
|
|
|
return new ProvidersApi(DEFAULT_CONFIG).providersSamlImportMetadataCreate({
|
2021-04-01 17:28:12 +00:00
|
|
|
file: file,
|
|
|
|
name: data.name,
|
|
|
|
authorizationFlow: data.authorizationFlow,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Name`} ?required=${true} name="name">
|
|
|
|
<input type="text" class="pf-c-form-control" required />
|
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`Authorization flow`}
|
2021-04-01 17:28:12 +00:00
|
|
|
?required=${true}
|
2021-08-03 15:52:21 +00:00
|
|
|
name="authorizationFlow"
|
|
|
|
>
|
2021-04-01 17:28:12 +00:00
|
|
|
<select class="pf-c-form-control">
|
2021-08-03 15:52:21 +00:00
|
|
|
${until(
|
|
|
|
new FlowsApi(DEFAULT_CONFIG)
|
|
|
|
.flowsInstancesList({
|
|
|
|
ordering: "pk",
|
|
|
|
designation: FlowsInstancesListDesignationEnum.Authorization,
|
|
|
|
})
|
|
|
|
.then((flows) => {
|
|
|
|
return flows.results.map((flow) => {
|
|
|
|
return html`<option value=${flow.slug}>
|
|
|
|
${flow.name} (${flow.slug})
|
|
|
|
</option>`;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
html`<option>${t`Loading...`}</option>`,
|
|
|
|
)}
|
2021-04-01 17:28:12 +00:00
|
|
|
</select>
|
2021-08-03 15:52:21 +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>
|
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Metadata`} name="flow">
|
|
|
|
<input type="file" value="" class="pf-c-form-control" />
|
2021-04-01 17:28:12 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
}
|