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, ProviderTypeEnum, SourceType, SourcesApi, UserMatchingModeEnum, } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../../api/Config"; import "../../../elements/CodeMirror"; 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``} ${this.providerType.slug === ProviderTypeEnum.Openidconnect ? html`

${t`OIDC well-known configuration URL. Can be used to automatically configure the URLs above.`}

${t`JSON Web Key URL. Keys from the URL will be used to validate JWTs from this source.`}

${t`Raw JWKS data.`}

` : html``}
`; } renderForm(): TemplateResult { return html`

${t`Path template for users created. Use placeholders like \`%(slug)s\` to insert the source slug.`}

${t`Protocol settings`}

${t`Additional scopes to be passed to the OAuth Provider, separated by space.`}

${this.renderUrlOptions()} ${t`Flow settings`}

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

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

`; } }