import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { until } from "lit/directives/until.js"; import { FlowsApi, FlowsInstancesListDesignationEnum, OAuthSource, OAuthSourceRequest, SourceType, SourcesApi, UserMatchingModeEnum, } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../../api/Config"; import "../../../elements/forms/FormGroup"; import "../../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../../elements/forms/ModelForm"; import { first } from "../../../utils"; @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 | null = null; 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`Additional scopes to be passed to the OAuth Provider, separated by space.`}

${t`Flow settings`}

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

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

`; } }