import { OAuthSource, SourcesApi, FlowsApi, UserMatchingModeEnum, OAuthSourceRequest, FlowsInstancesListDesignationEnum, SourceType, } from "authentik-api"; import { t } from "@lingui/macro"; import { customElement, property } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { DEFAULT_CONFIG } from "../../../api/Config"; import "../../../elements/forms/FormGroup"; import "../../../elements/forms/HorizontalFormElement"; import { ifDefined } from "lit-html/directives/if-defined"; import { until } from "lit-html/directives/until"; import { first } from "../../../utils"; import { ModelForm } from "../../../elements/forms/ModelForm"; @customElement("ak-source-oauth-form") export class OAuthSourceForm extends ModelForm { loadInstance(pk: string): Promise { return new SourcesApi(DEFAULT_CONFIG) .sourcesOauthRetrieve({ slug: pk, }) .then((source) => { this.providerType = source.type; return source; }); } _modelName?: string; @property() set modelName(v: string | undefined) { this._modelName = v; new SourcesApi(DEFAULT_CONFIG).sourcesOauthSourceTypesList({ name: v?.replace("oauthsource", ""), }).then((type) => { this.providerType = type[0]; }); } get modelName(): string|undefined { return this._modelName; } @property({ attribute: false }) providerType?: SourceType; getSuccessMessage(): string { if (this.instance) { return t`Successfully updated source.`; } else { return t`Successfully created source.`; } } send = (data: OAuthSource): Promise => { data.providerType = this.providerType?.slug || ""; if (this.instance?.slug) { return new SourcesApi(DEFAULT_CONFIG).sourcesOauthPartialUpdate({ slug: this.instance.slug, patchedOAuthSourceRequest: data, }); } else { return new SourcesApi(DEFAULT_CONFIG).sourcesOauthCreate({ oAuthSourceRequest: data as unknown as OAuthSourceRequest, }); } }; renderUrlOptions(): TemplateResult { if (!this.providerType?.urlsCustomizable) { return html``; } return html` ${t`URL settings`}

${t`URL the user is redirect to to consent the authorization.`}

${t`URL used by authentik to retrieve tokens.`}

${t`URL used by authentik to get user information.`}

${this.providerType.requestTokenUrl ? html`

${t`URL used to request the initial token. This URL is only required for OAuth 1.`}

` : html``}
`; } renderForm(): TemplateResult { return html`
${t`Protocol settings`}
${this.renderUrlOptions()} ${t`Flow settings`}

${t`Flow to use when authenticating existing users.`}

${t`Flow to use when enrolling new users.`}

`; } }