core: applications backchannel provider (#5449)
* backchannel applications Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add webui Signed-off-by: Jens Langhammer <jens@goauthentik.io> * include assigned app in provider Signed-off-by: Jens Langhammer <jens@goauthentik.io> * improve backchannel provider list display Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make ldap provider compatible Signed-off-by: Jens Langhammer <jens@goauthentik.io> * show backchannel providers in app view Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make backchannel required for SCIM Signed-off-by: Jens Langhammer <jens@goauthentik.io> * cleanup api Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * Apply suggestions from code review Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com> Signed-off-by: Jens L. <jens@beryju.org> * update docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Signed-off-by: Jens L. <jens@beryju.org> Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com>
This commit is contained in:
		@ -1,3 +1,4 @@
 | 
			
		||||
import "@goauthentik/admin/applications/ProviderSelectModal";
 | 
			
		||||
import { DEFAULT_CONFIG, config } from "@goauthentik/common/api/config";
 | 
			
		||||
import { first, groupBy } from "@goauthentik/common/utils";
 | 
			
		||||
import { rootInterface } from "@goauthentik/elements/Base";
 | 
			
		||||
@ -12,7 +13,7 @@ import "@goauthentik/elements/forms/SearchSelect";
 | 
			
		||||
import { t } from "@lingui/macro";
 | 
			
		||||
 | 
			
		||||
import { TemplateResult, html } from "lit";
 | 
			
		||||
import { customElement, property } from "lit/decorators.js";
 | 
			
		||||
import { customElement, property, state } from "lit/decorators.js";
 | 
			
		||||
import { ifDefined } from "lit/directives/if-defined.js";
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
@ -32,12 +33,16 @@ export class ApplicationForm extends ModelForm<Application, string> {
 | 
			
		||||
            slug: pk,
 | 
			
		||||
        });
 | 
			
		||||
        this.clearIcon = false;
 | 
			
		||||
        this.backchannelProviders = app.backchannelProvidersObj || [];
 | 
			
		||||
        return app;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @property({ attribute: false })
 | 
			
		||||
    provider?: number;
 | 
			
		||||
 | 
			
		||||
    @state()
 | 
			
		||||
    backchannelProviders: Provider[] = [];
 | 
			
		||||
 | 
			
		||||
    @property({ type: Boolean })
 | 
			
		||||
    clearIcon = false;
 | 
			
		||||
 | 
			
		||||
@ -51,6 +56,7 @@ export class ApplicationForm extends ModelForm<Application, string> {
 | 
			
		||||
 | 
			
		||||
    async send(data: Application): Promise<Application | void> {
 | 
			
		||||
        let app: Application;
 | 
			
		||||
        data.backchannelProviders = this.backchannelProviders.map((p) => p.pk);
 | 
			
		||||
        if (this.instance) {
 | 
			
		||||
            app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsUpdate({
 | 
			
		||||
                slug: this.instance.slug,
 | 
			
		||||
@ -143,6 +149,47 @@ export class ApplicationForm extends ModelForm<Application, string> {
 | 
			
		||||
                    ${t`Select a provider that this application should use.`}
 | 
			
		||||
                </p>
 | 
			
		||||
            </ak-form-element-horizontal>
 | 
			
		||||
 | 
			
		||||
            <ak-form-element-horizontal
 | 
			
		||||
                label=${t`Backchannel providers`}
 | 
			
		||||
                name="backchannelProviders"
 | 
			
		||||
            >
 | 
			
		||||
                <div class="pf-c-input-group">
 | 
			
		||||
                    <ak-provider-select-table
 | 
			
		||||
                        ?backchannelOnly=${true}
 | 
			
		||||
                        .confirm=${(items: Provider[]) => {
 | 
			
		||||
                            this.backchannelProviders = items;
 | 
			
		||||
                            this.requestUpdate();
 | 
			
		||||
                            return Promise.resolve();
 | 
			
		||||
                        }}
 | 
			
		||||
                    >
 | 
			
		||||
                        <button slot="trigger" class="pf-c-button pf-m-control" type="button">
 | 
			
		||||
                            <i class="fas fa-plus" aria-hidden="true"></i>
 | 
			
		||||
                        </button>
 | 
			
		||||
                    </ak-provider-select-table>
 | 
			
		||||
                    <div class="pf-c-form-control">
 | 
			
		||||
                        <ak-chip-group>
 | 
			
		||||
                            ${this.backchannelProviders.map((provider) => {
 | 
			
		||||
                                return html`<ak-chip
 | 
			
		||||
                                    .removable=${true}
 | 
			
		||||
                                    value=${ifDefined(provider.pk)}
 | 
			
		||||
                                    @remove=${() => {
 | 
			
		||||
                                        const idx = this.backchannelProviders.indexOf(provider);
 | 
			
		||||
                                        this.backchannelProviders.splice(idx, 1);
 | 
			
		||||
                                        this.requestUpdate();
 | 
			
		||||
                                    }}
 | 
			
		||||
                                >
 | 
			
		||||
                                    ${provider.name}
 | 
			
		||||
                                </ak-chip>`;
 | 
			
		||||
                            })}
 | 
			
		||||
                        </ak-chip-group>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>
 | 
			
		||||
                <p class="pf-c-form__helper-text">
 | 
			
		||||
                    ${t`Select backchannel providers which augment the functionality of the main provider.`}
 | 
			
		||||
                </p>
 | 
			
		||||
            </ak-form-element-horizontal>
 | 
			
		||||
 | 
			
		||||
            <ak-form-element-horizontal
 | 
			
		||||
                label=${t`Policy engine mode`}
 | 
			
		||||
                ?required=${true}
 | 
			
		||||
 | 
			
		||||
@ -21,6 +21,7 @@ import PFButton from "@patternfly/patternfly/components/Button/button.css";
 | 
			
		||||
import PFCard from "@patternfly/patternfly/components/Card/card.css";
 | 
			
		||||
import PFContent from "@patternfly/patternfly/components/Content/content.css";
 | 
			
		||||
import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css";
 | 
			
		||||
import PFList from "@patternfly/patternfly/components/List/list.css";
 | 
			
		||||
import PFPage from "@patternfly/patternfly/components/Page/page.css";
 | 
			
		||||
import PFGrid from "@patternfly/patternfly/layouts/Grid/grid.css";
 | 
			
		||||
import PFBase from "@patternfly/patternfly/patternfly-base.css";
 | 
			
		||||
@ -65,7 +66,17 @@ export class ApplicationViewPage extends AKElement {
 | 
			
		||||
    missingOutpost = false;
 | 
			
		||||
 | 
			
		||||
    static get styles(): CSSResult[] {
 | 
			
		||||
        return [PFBase, PFBanner, PFPage, PFContent, PFButton, PFDescriptionList, PFGrid, PFCard];
 | 
			
		||||
        return [
 | 
			
		||||
            PFBase,
 | 
			
		||||
            PFList,
 | 
			
		||||
            PFBanner,
 | 
			
		||||
            PFPage,
 | 
			
		||||
            PFContent,
 | 
			
		||||
            PFButton,
 | 
			
		||||
            PFDescriptionList,
 | 
			
		||||
            PFGrid,
 | 
			
		||||
            PFCard,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    render(): TemplateResult {
 | 
			
		||||
@ -121,6 +132,35 @@ export class ApplicationViewPage extends AKElement {
 | 
			
		||||
                                          </dd>
 | 
			
		||||
                                      </div>`
 | 
			
		||||
                                    : html``}
 | 
			
		||||
                                ${(this.application.backchannelProvidersObj || []).length > 0
 | 
			
		||||
                                    ? html`<div class="pf-c-description-list__group">
 | 
			
		||||
                                          <dt class="pf-c-description-list__term">
 | 
			
		||||
                                              <span class="pf-c-description-list__text"
 | 
			
		||||
                                                  >${t`Backchannel Providers`}</span
 | 
			
		||||
                                              >
 | 
			
		||||
                                          </dt>
 | 
			
		||||
                                          <dd class="pf-c-description-list__description">
 | 
			
		||||
                                              <div class="pf-c-description-list__text">
 | 
			
		||||
                                                  <ul class="pf-c-list">
 | 
			
		||||
                                                      ${this.application.backchannelProvidersObj.map(
 | 
			
		||||
                                                          (provider) => {
 | 
			
		||||
                                                              return html`
 | 
			
		||||
                                                                  <li>
 | 
			
		||||
                                                                      <a
 | 
			
		||||
                                                                          href="#/core/providers/${provider.pk}"
 | 
			
		||||
                                                                      >
 | 
			
		||||
                                                                          ${provider.name}
 | 
			
		||||
                                                                          (${provider.verboseName})
 | 
			
		||||
                                                                      </a>
 | 
			
		||||
                                                                  </li>
 | 
			
		||||
                                                              `;
 | 
			
		||||
                                                          },
 | 
			
		||||
                                                      )}
 | 
			
		||||
                                                  </ul>
 | 
			
		||||
                                              </div>
 | 
			
		||||
                                          </dd>
 | 
			
		||||
                                      </div>`
 | 
			
		||||
                                    : html``}
 | 
			
		||||
                                <div class="pf-c-description-list__group">
 | 
			
		||||
                                    <dt class="pf-c-description-list__term">
 | 
			
		||||
                                        <span class="pf-c-description-list__text"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										88
									
								
								web/src/admin/applications/ProviderSelectModal.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								web/src/admin/applications/ProviderSelectModal.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,88 @@
 | 
			
		||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
 | 
			
		||||
import { uiConfig } from "@goauthentik/common/ui/config";
 | 
			
		||||
import "@goauthentik/elements/buttons/SpinnerButton";
 | 
			
		||||
import { PaginatedResponse } from "@goauthentik/elements/table/Table";
 | 
			
		||||
import { TableColumn } from "@goauthentik/elements/table/Table";
 | 
			
		||||
import { TableModal } from "@goauthentik/elements/table/TableModal";
 | 
			
		||||
 | 
			
		||||
import { t } from "@lingui/macro";
 | 
			
		||||
 | 
			
		||||
import { TemplateResult, html } from "lit";
 | 
			
		||||
import { customElement, property } from "lit/decorators.js";
 | 
			
		||||
 | 
			
		||||
import { Provider, ProvidersApi } from "@goauthentik/api";
 | 
			
		||||
 | 
			
		||||
@customElement("ak-provider-select-table")
 | 
			
		||||
export class ProviderSelectModal extends TableModal<Provider> {
 | 
			
		||||
    checkbox = true;
 | 
			
		||||
    checkboxChip = true;
 | 
			
		||||
 | 
			
		||||
    searchEnabled(): boolean {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @property({ type: Boolean })
 | 
			
		||||
    backchannelOnly = false;
 | 
			
		||||
 | 
			
		||||
    @property()
 | 
			
		||||
    confirm!: (selectedItems: Provider[]) => Promise<unknown>;
 | 
			
		||||
 | 
			
		||||
    order = "name";
 | 
			
		||||
 | 
			
		||||
    async apiEndpoint(page: number): Promise<PaginatedResponse<Provider>> {
 | 
			
		||||
        return new ProvidersApi(DEFAULT_CONFIG).providersAllList({
 | 
			
		||||
            ordering: this.order,
 | 
			
		||||
            page: page,
 | 
			
		||||
            pageSize: (await uiConfig()).pagination.perPage,
 | 
			
		||||
            search: this.search || "",
 | 
			
		||||
            backchannelOnly: this.backchannelOnly,
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    columns(): TableColumn[] {
 | 
			
		||||
        return [new TableColumn(t`Name`, "username"), new TableColumn(t`Type`)];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    row(item: Provider): TemplateResult[] {
 | 
			
		||||
        return [
 | 
			
		||||
            html`<div>
 | 
			
		||||
                <div>${item.name}</div>
 | 
			
		||||
            </div>`,
 | 
			
		||||
            html`${item.verboseName}`,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    renderSelectedChip(item: Provider): TemplateResult {
 | 
			
		||||
        return html`${item.name}`;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    renderModalInner(): TemplateResult {
 | 
			
		||||
        return html`<section class="pf-c-modal-box__header pf-c-page__main-section pf-m-light">
 | 
			
		||||
                <div class="pf-c-content">
 | 
			
		||||
                    <h1 class="pf-c-title pf-m-2xl">
 | 
			
		||||
                        ${t`Select providers to add to application`}
 | 
			
		||||
                    </h1>
 | 
			
		||||
                </div>
 | 
			
		||||
            </section>
 | 
			
		||||
            <section class="pf-c-modal-box__body pf-m-light">${this.renderTable()}</section>
 | 
			
		||||
            <footer class="pf-c-modal-box__footer">
 | 
			
		||||
                <ak-spinner-button
 | 
			
		||||
                    .callAction=${async () => {
 | 
			
		||||
                        await this.confirm(this.selectedElements);
 | 
			
		||||
                        this.open = false;
 | 
			
		||||
                    }}
 | 
			
		||||
                    class="pf-m-primary"
 | 
			
		||||
                >
 | 
			
		||||
                    ${t`Add`} </ak-spinner-button
 | 
			
		||||
                > 
 | 
			
		||||
                <ak-spinner-button
 | 
			
		||||
                    .callAction=${async () => {
 | 
			
		||||
                        this.open = false;
 | 
			
		||||
                    }}
 | 
			
		||||
                    class="pf-m-secondary"
 | 
			
		||||
                >
 | 
			
		||||
                    ${t`Cancel`}
 | 
			
		||||
                </ak-spinner-button>
 | 
			
		||||
            </footer>`;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -82,24 +82,29 @@ export class ProviderListPage extends TablePage<Provider> {
 | 
			
		||||
        </ak-forms-delete-bulk>`;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    row(item: Provider): TemplateResult[] {
 | 
			
		||||
        let app = html``;
 | 
			
		||||
        if (item.component === "ak-provider-scim-form") {
 | 
			
		||||
            app = html`<i class="pf-icon pf-icon-ok pf-m-success"></i>
 | 
			
		||||
                ${t`No application required.`}`;
 | 
			
		||||
        } else if (!item.assignedApplicationName) {
 | 
			
		||||
            app = html`<i class="pf-icon pf-icon-warning-triangle pf-m-warning"></i>
 | 
			
		||||
                ${t`Warning: Provider not assigned to any application.`}`;
 | 
			
		||||
        } else {
 | 
			
		||||
            app = html`<i class="pf-icon pf-icon-ok pf-m-success"></i>
 | 
			
		||||
    rowApp(item: Provider): TemplateResult {
 | 
			
		||||
        if (item.assignedApplicationName) {
 | 
			
		||||
            return html`<i class="pf-icon pf-icon-ok pf-m-success"></i>
 | 
			
		||||
                ${t`Assigned to application `}
 | 
			
		||||
                <a href="#/core/applications/${item.assignedApplicationSlug}"
 | 
			
		||||
                    >${item.assignedApplicationName}</a
 | 
			
		||||
                >`;
 | 
			
		||||
        }
 | 
			
		||||
        if (item.assignedBackchannelApplicationName) {
 | 
			
		||||
            return html`<i class="pf-icon pf-icon-ok pf-m-success"></i>
 | 
			
		||||
                ${t`Assigned to application (backchannel) `}
 | 
			
		||||
                <a href="#/core/applications/${item.assignedBackchannelApplicationSlug}"
 | 
			
		||||
                    >${item.assignedBackchannelApplicationName}</a
 | 
			
		||||
                >`;
 | 
			
		||||
        }
 | 
			
		||||
        return html`<i class="pf-icon pf-icon-warning-triangle pf-m-warning"></i>
 | 
			
		||||
            ${t`Warning: Provider not assigned to any application.`}`;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    row(item: Provider): TemplateResult[] {
 | 
			
		||||
        return [
 | 
			
		||||
            html`<a href="#/core/providers/${item.pk}"> ${item.name} </a>`,
 | 
			
		||||
            app,
 | 
			
		||||
            this.rowApp(item),
 | 
			
		||||
            html`${item.verboseName}`,
 | 
			
		||||
            html`<ak-forms-modal>
 | 
			
		||||
                <span slot="submit"> ${t`Update`} </span>
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user