"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BASE_SCOPE = exports.BASE_AUDIENCE = exports.BASE_CLIENT_SECRET = exports.BASE_CLIENT_ID = exports.BASE_TOKEN_URL = exports.BASE_SUBJECT_TOKEN_STATIC_TOKEN = exports.BASE_SUBJECT_TOKEN_TYPE = exports.BASE_SUBJECT_TOKEN_SOURCE = exports.authSections = exports.ClientAuthMethod = void 0;
const index_js_1 = require("../../../types/index.js");
const restapiintegration_js_1 = require("./restapiintegration.js");
var ClientAuthMethod;
(function (ClientAuthMethod) {
    ClientAuthMethod["BASIC"] = "BASIC";
    ClientAuthMethod["BEARER"] = "BEARER";
    ClientAuthMethod["POST"] = "POST";
})(ClientAuthMethod || (exports.ClientAuthMethod = ClientAuthMethod = {}));
const AUTH_METHODS_TO_TYPES = {
    basic: index_js_1.IntegrationAuthType.BASIC,
    firebase: index_js_1.IntegrationAuthType.FIREBASE,
    oauth: index_js_1.IntegrationAuthType.OAUTH2_CLIENT_CREDS,
    bearer: index_js_1.IntegrationAuthType.BEARER,
    apiKey: index_js_1.IntegrationAuthType.API_KEY,
    apiKeyForm: index_js_1.IntegrationAuthType.API_KEY_FORM,
    tokenPrefixed: index_js_1.IntegrationAuthType.TOKEN_PREFIXED,
    oauth2BringYourOwn: index_js_1.IntegrationAuthType.OAUTH2_CODE,
    oauth2SuperblocksClient: index_js_1.IntegrationAuthType.OAUTH2_CODE,
    // those matches proto types auth.method.case
    passwordGrantFlow: index_js_1.NewAuthType.OAUTH2_PASSWORD_GRANT_FLOW,
    authorizationCodeFlow: index_js_1.NewAuthType.OAUTH2_AUTH_CODE_FLOW,
    clientCredentialsFlow: index_js_1.NewAuthType.OAUTH2_CLIENT_CREDS_FLOW,
    tokenExchangeFlow: index_js_1.NewAuthType.OAUTH2_TOKEN_EXCHANGE_FLOW
};
const authSections = ({ startVersion, endVersion, pluginId, pluginName, defaultMethod, enabledMethods, allowNone = true, fieldNamesToHide = [], isProto = false, 
// allow caller to provide optional customized auth items
prependItems = [] }) => {
    // Extract display name override before filtering methods
    const apiKeyFormDisplayName = enabledMethods.apiKeyFormDisplayName;
    // Filter out any disabled methods (exclude non-method keys like apiKeyFormDisplayName)
    enabledMethods = Object.keys(enabledMethods).reduce((acc, key) => {
        if (enabledMethods[key] && key !== 'apiKeyFormDisplayName') {
            acc[key] = enabledMethods[key];
        }
        return acc;
    }, {});
    // If there are no enabled methods, return an empty array
    const enabledMethodKeys = Object.keys(enabledMethods);
    if (enabledMethodKeys.length === 0) {
        return [];
    }
    let authTypeInitialValue;
    // If default method is specified and it's enabled, use it. Otherwise, if allowNone is true, use none. Otherwise, use the first enabled method.
    if (defaultMethod && enabledMethods[defaultMethod]) {
        authTypeInitialValue = AUTH_METHODS_TO_TYPES[defaultMethod];
    }
    else if (allowNone) {
        authTypeInitialValue = index_js_1.IntegrationAuthType.NONE;
    }
    else {
        authTypeInitialValue = AUTH_METHODS_TO_TYPES[enabledMethodKeys[0]];
    }
    if (!authTypeInitialValue) {
        throw new Error(`Could not determine initial auth type for plugin ${pluginId} given default method ${defaultMethod} and enabled methods ${enabledMethodKeys}`);
    }
    const formSections = [];
    const authFields = [];
    addField(authFields, prependItems, fieldNamesToHide);
    // oauth2SuperblocksClient is google sheet
    // google sheet defines Authentication dropdown at parent level gsheets.ts
    if (!enabledMethods.oauth2SuperblocksClient) {
        addField(authFields, [
            {
                name: isProto ? 'connection.auth.method.case' : 'authType',
                label: 'Authentication',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.DROPDOWN,
                initialValue: authTypeInitialValue,
                options: authTypeOptions({ enabledMethods, allowNone, isProto, apiKeyFormDisplayName }),
                disabled: !allowNone && enabledMethodKeys.length === 1
            }
        ], fieldNamesToHide);
    }
    if (enabledMethods.basic) {
        let usernameLabel = 'Username';
        let usernamePlaceholder = 'username';
        let passwordLabel = 'Password';
        let passwordPlaceholder = 'password';
        if (typeof enabledMethods.basic === 'object' && enabledMethods.basic.username) {
            usernameLabel = enabledMethods.basic.username.label ?? usernameLabel;
            usernamePlaceholder = enabledMethods.basic.username.placeholder ?? usernamePlaceholder;
        }
        if (typeof enabledMethods.basic === 'object' && enabledMethods.basic.password) {
            passwordLabel = enabledMethods.basic.password.label ?? passwordLabel;
            passwordPlaceholder = enabledMethods.basic.password.placeholder ?? passwordPlaceholder;
        }
        addField(authFields, [
            {
                label: 'Share username/password across all users',
                // Explicitly use a different var from useFixedPasswordCreds since
                // this is semantically pretty different for this auth type. They
                // default to opposite values for example.
                name: 'authConfig.shareBasicAuthCreds',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CHECKBOX,
                tooltip: {
                    markdownText: `When enabled, all users will share a fixed set of
      credentials. When disabled, users will be prompted to enter a
      username/password to authenticate themselves with this integration.`
                },
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.BASIC]
                    }
                },
                initialValue: true
            },
            {
                label: usernameLabel,
                name: 'authConfig.username',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                placeholder: usernamePlaceholder,
                singleLine: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.BASIC],
                        // Adding undefined is a bit of a hack here to show this field
                        // when the default value is set. This will be removed soon.
                        'authConfig.shareBasicAuthCreds': ['true', 'undefined']
                    }
                }
            },
            {
                label: passwordLabel,
                name: 'authConfig.password',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                placeholder: passwordPlaceholder,
                dataType: index_js_1.InputDataType.PASSWORD,
                singleLine: false,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.BASIC],
                        // Adding undefined is a bit of a hack here to show this field
                        // when the default value is set. This will be removed soon.
                        'authConfig.shareBasicAuthCreds': ['true', 'undefined']
                    }
                }
            },
            {
                label: '',
                messageTemplate: `The authorization header will be automatically generated when you send requests.
          Learn more about [Basic Auth](https://docs.superblocks.com/integrations/auth/authentication-types) authorization.`,
                name: 'HTTPBasicAlert',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.ALERT,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.BASIC]
                    }
                }
            }
        ], fieldNamesToHide);
    }
    if (enabledMethods.bearer) {
        addField(authFields, [
            {
                label: 'Token',
                name: 'authConfig.bearerToken',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                rules: [{ required: true, message: 'Bearer token is required' }],
                placeholder: `bearer-token`,
                dataType: index_js_1.InputDataType.PASSWORD,
                tooltip: {
                    markdownText: `Specify the bearer token to be used for authentication`
                },
                singleLine: false,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.BEARER]
                    }
                }
            }
        ], fieldNamesToHide);
    }
    if (enabledMethods.tokenPrefixed) {
        addField(authFields, [
            {
                label: 'Token',
                name: 'authConfig.token',
                startVersion: restapiintegration_js_1.RestApiIntegrationPluginVersions.V13,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                rules: [{ required: true, message: 'Token is required' }],
                placeholder: `token`,
                dataType: index_js_1.InputDataType.PASSWORD,
                tooltip: {
                    markdownText: `Specify the token to be used for authentication`
                },
                singleLine: false,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.TOKEN_PREFIXED]
                    }
                }
            }
        ], fieldNamesToHide);
        if (typeof enabledMethods.tokenPrefixed === 'object' && enabledMethods.tokenPrefixed.prefix) {
            addField(authFields, [
                {
                    label: '',
                    name: 'authConfig.prefix',
                    startVersion: restapiintegration_js_1.RestApiIntegrationPluginVersions.V13,
                    componentType: index_js_1.FormComponentType.INPUT_TEXT,
                    initialValue: enabledMethods.tokenPrefixed.prefix,
                    display: {
                        show: {
                            authType: [index_js_1.IntegrationAuthType.TOKEN_PREFIXED]
                        }
                    },
                    hidden: true,
                    disabled: true
                }
            ], fieldNamesToHide);
        }
    }
    if (enabledMethods.apiKeyForm) {
        for (const apiKey of enabledMethods.apiKeyForm) {
            addField(authFields, [
                {
                    label: '',
                    name: `authConfig.apiKeys.${apiKey.key}.header`,
                    startVersion: restapiintegration_js_1.RestApiIntegrationPluginVersions.V13,
                    componentType: index_js_1.FormComponentType.INPUT_TEXT,
                    initialValue: apiKey.header,
                    display: {
                        show: {
                            authType: [index_js_1.IntegrationAuthType.API_KEY_FORM]
                        }
                    },
                    hidden: true,
                    disabled: true
                }
            ], fieldNamesToHide);
            addField(authFields, [
                {
                    label: '',
                    name: `authConfig.apiKeys.${apiKey.key}.prefix`,
                    startVersion: restapiintegration_js_1.RestApiIntegrationPluginVersions.V13,
                    componentType: index_js_1.FormComponentType.INPUT_TEXT,
                    initialValue: apiKey.valuePrefix || '',
                    display: {
                        show: {
                            authType: [index_js_1.IntegrationAuthType.API_KEY_FORM]
                        }
                    },
                    hidden: true,
                    disabled: true
                }
            ], fieldNamesToHide);
            addField(authFields, [
                {
                    label: apiKey.label,
                    name: `authConfig.apiKeys.${apiKey.key}.token`,
                    startVersion: restapiintegration_js_1.RestApiIntegrationPluginVersions.V13,
                    componentType: index_js_1.FormComponentType.INPUT_TEXT,
                    dataType: index_js_1.InputDataType.PASSWORD,
                    singleLine: false,
                    rules: [
                        {
                            required: apiKey.required ?? true,
                            message: `${apiKey.label} is required`
                        }
                    ],
                    ...(apiKey.tooltip ? { tooltip: apiKey.tooltip } : {}),
                    display: {
                        show: {
                            authType: [index_js_1.IntegrationAuthType.API_KEY_FORM]
                        }
                    }
                }
            ], fieldNamesToHide);
        }
    }
    if (enabledMethods.apiKey) {
        addField(authFields, [
            {
                label: 'Key',
                name: 'authConfig.key',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                rules: [{ required: true, message: 'Key is required' }],
                placeholder: `api key`,
                tooltip: { markdownText: apiKeyMarkdownText(pluginId) },
                singleLine: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.API_KEY]
                    }
                }
            },
            {
                label: 'Value',
                name: 'authConfig.value',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                rules: [{ required: true, message: 'Value is required' }],
                placeholder: `value`,
                dataType: index_js_1.InputDataType.PASSWORD,
                tooltip: {
                    markdownText: `The value corresponding to the API key`
                },
                singleLine: false,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.API_KEY]
                    }
                }
            }
        ], fieldNamesToHide);
        if (pluginId === index_js_1.ExtendedIntegrationPluginId.REST_API) {
            addField(authFields, [
                {
                    label: 'Add to',
                    name: 'authConfig.method',
                    startVersion: startVersion,
                    componentType: index_js_1.FormComponentType.DROPDOWN,
                    initialValue: index_js_1.ApiKeyMethod.HEADER,
                    options: apiKeyAuthOptions(pluginId),
                    tooltip: {
                        markdownText: `How the API key is passed to the API (as a header or as a query parameter)`
                    },
                    singleLine: true,
                    display: {
                        show: {
                            authType: [index_js_1.IntegrationAuthType.API_KEY]
                        }
                    }
                }
            ], fieldNamesToHide);
        }
        else if (pluginId === index_js_1.ExtendedIntegrationPluginId.GRAPHQL) {
            addField(authFields, [
                {
                    label: '',
                    name: 'authConfig.method',
                    startVersion,
                    componentType: index_js_1.FormComponentType.INPUT_TEXT,
                    initialValue: index_js_1.ApiKeyMethod.HEADER,
                    hidden: true,
                    display: {
                        show: {
                            authType: [index_js_1.IntegrationAuthType.API_KEY]
                        }
                    }
                }
            ], fieldNamesToHide);
        }
    }
    if (enabledMethods.firebase) {
        addField(authFields, [
            {
                label: '',
                messageTemplate: `**Where do I get my firebase credentials and allow access to Superblocks?** [Superblocks - Firebase Docs](https://docs.superblocks.com/integrations/auth/firebase)\\
  Note: REST APIs authenticated with firebase cannot be used in Superblocks Workflows & Scheduled Jobs since both can be called headlessly without user interaction.`,
                name: 'FirebaseAlert',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.ALERT,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.FIREBASE]
                    }
                }
            },
            {
                label: 'API config',
                name: 'authConfig.apiKey',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CODE_EDITOR,
                language: index_js_1.EditorLanguage.JSON,
                tooltip: {
                    markdownText: `The API config can be found through the Firebase
      portal. It's used to identify your app to Firebase.`
                },
                placeholder: `{
  apiKey: "",
  authDomain: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: "",
  measurementId: ""
  }
      `,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.FIREBASE]
                    }
                }
            },
            {
                label: 'Enable login with email/password',
                name: 'authConfig.email',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CHECKBOX,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.FIREBASE]
                    }
                },
                initialValue: true
            },
            {
                label: 'Enable login with Google',
                name: 'authConfig.google',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CHECKBOX,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.FIREBASE]
                    }
                }
            },
            {
                label: '',
                messageTemplate: `Use **{{firebase.token}}** below to refer to the firebase
      authentication token & use **{{firebase.userId}}** to refer to the
      currently authenticated user's ID.`,
                name: 'FirebaseAlertToken',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.ALERT,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.FIREBASE]
                    }
                }
            }
        ], fieldNamesToHide);
    }
    // Following fields are for newly defined plugin (as proto) and their datasource configurations
    // TODO make this composite pattern
    if (enabledMethods.passwordGrantFlow || enabledMethods.clientCredentialsFlow) {
        authFields.push({
            label: 'Token URL',
            name: 'connection.auth.method.value.tokenUrl',
            startVersion: startVersion,
            componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
            rules: [{ required: true, message: 'Token URL is required' }],
            tooltip: {
                markdownText: `The endpoint for authorization server. This is used to get the access token.`
            },
            singleLine: true,
            display: {
                show: {
                    'connection.auth.method.case': ['passwordGrantFlow', 'clientCredentialsFlow']
                }
            },
            placeholder: 'https://login.salesforce.com/services/oauth2/token'
        }, {
            label: 'Consumer key',
            name: 'connection.auth.method.value.clientId',
            startVersion: startVersion,
            componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
            placeholder: `my consumer key`,
            rules: [{ required: true, message: 'Consumer Key is required' }],
            tooltip: {
                markdownText: `A public identifier used to identify this Salesforce consumer
    to the authorization/token servers.`
            },
            singleLine: true,
            display: {
                show: {
                    'connection.auth.method.case': ['passwordGrantFlow', 'clientCredentialsFlow']
                }
            }
        }, {
            label: 'Consumer secret',
            name: 'connection.auth.method.value.clientSecret',
            startVersion: startVersion,
            componentType: index_js_1.FormComponentType.INPUT_TEXT,
            rules: [{ required: true, message: 'Consumer secret is required' }],
            placeholder: `my consumer secret`,
            dataType: index_js_1.InputDataType.PASSWORD,
            tooltip: {
                markdownText: `A secret shared between the Salesforce consumer and the
    authorizing/token servers to verify the Consumer Key.`
            },
            singleLine: false,
            display: {
                show: {
                    'connection.auth.method.case': ['passwordGrantFlow', 'clientCredentialsFlow']
                }
            }
        }, {
            label: 'Username',
            name: 'connection.auth.method.value.username',
            startVersion: startVersion,
            componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
            placeholder: `username`,
            singleLine: true,
            rules: [{ required: true, message: 'Username is required' }],
            display: {
                show: {
                    'connection.auth.method.case': ['passwordGrantFlow']
                }
            }
        }, {
            label: 'Password',
            name: 'connection.auth.method.value.password',
            startVersion: startVersion,
            componentType: index_js_1.FormComponentType.INPUT_TEXT,
            placeholder: 'password',
            dataType: index_js_1.InputDataType.PASSWORD,
            singleLine: false,
            rules: [{ required: true, message: 'Password is required' }],
            display: {
                show: {
                    'connection.auth.method.case': ['passwordGrantFlow']
                }
            }
        });
    }
    // following is used by old datasource configurations (defined using typescript)
    if (enabledMethods.oauth) {
        addField(authFields, [
            {
                ...BASE_OAUTH_BINDING_ALERT,
                startVersion,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT]
                    }
                }
            },
            {
                ...BASE_OAUTH_BINDING_ALERT_AUTH_CODE,
                startVersion,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            },
            {
                label: 'Callback URL',
                name: 'oauth-callback-alert',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                disabled: true,
                immutable: true,
                initialValue: `<%= origin %>/${index_js_1.OAUTH_CALLBACK_PATH}`,
                tooltip: {
                    markdownText: `This is where users will be redirected after authorization. Add this to your application's list of allowed callback URLs.`
                },
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE, index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT]
                    }
                },
                enableCopy: true,
                singleLine: false
            },
            {
                label: 'Authorization URL',
                name: 'authConfig.authorizationUrl',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                rules: [{ required: true, message: 'Authorization URL is required' }],
                tooltip: {
                    markdownText: `The endpoint for authorization server. This is used to get the authorization code.`
                },
                singleLine: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT, index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                },
                placeholder: `https://example.com/login/oauth/authorize`
            },
            {
                ...exports.BASE_SUBJECT_TOKEN_SOURCE,
                startVersion,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE]
                    }
                }
            },
            {
                ...exports.BASE_SUBJECT_TOKEN_STATIC_TOKEN,
                startVersion,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE],
                        'authConfig.subjectTokenSource': ['SUBJECT_TOKEN_SOURCE_STATIC_TOKEN']
                    }
                }
            },
            {
                ...exports.BASE_SUBJECT_TOKEN_TYPE,
                startVersion,
                singleLine: false,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE]
                    }
                }
            },
            {
                ...exports.BASE_TOKEN_URL,
                startVersion,
                display: {
                    show: {
                        authType: [
                            index_js_1.IntegrationAuthType.OAUTH2_PASSWORD,
                            index_js_1.IntegrationAuthType.OAUTH2_CLIENT_CREDS,
                            index_js_1.IntegrationAuthType.OAUTH2_CODE,
                            index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE
                        ]
                    }
                }
            },
            {
                ...exports.BASE_CLIENT_ID,
                startVersion,
                display: {
                    show: {
                        authType: [
                            index_js_1.IntegrationAuthType.OAUTH2_PASSWORD,
                            index_js_1.IntegrationAuthType.OAUTH2_CLIENT_CREDS,
                            index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT,
                            index_js_1.IntegrationAuthType.OAUTH2_CODE
                        ]
                    }
                }
            },
            {
                ...exports.BASE_CLIENT_ID,
                startVersion,
                rules: [{ required: false }],
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE]
                    }
                }
            },
            {
                ...exports.BASE_CLIENT_SECRET,
                startVersion,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_PASSWORD, index_js_1.IntegrationAuthType.OAUTH2_CLIENT_CREDS, index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            },
            {
                ...exports.BASE_CLIENT_SECRET,
                startVersion,
                rules: [{ required: false }],
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE]
                    }
                }
            },
            {
                ...exports.BASE_AUDIENCE,
                startVersion,
                display: {
                    show: {
                        authType: [
                            index_js_1.IntegrationAuthType.OAUTH2_CLIENT_CREDS,
                            index_js_1.IntegrationAuthType.OAUTH2_CODE,
                            index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT,
                            index_js_1.IntegrationAuthType.OAUTH2_PASSWORD,
                            index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE
                        ]
                    }
                }
            },
            {
                // TODO: Ideally hide behind an advanced setting with audience.
                label: 'Prompt',
                name: 'authConfig.promptType',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                initialValue: 'consent',
                placeholder: 'consent',
                singleLine: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE, index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT]
                    }
                }
            },
            {
                ...exports.BASE_SCOPE,
                startVersion,
                display: {
                    show: {
                        authType: [
                            index_js_1.IntegrationAuthType.OAUTH2_CLIENT_CREDS,
                            index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT,
                            index_js_1.IntegrationAuthType.OAUTH2_CODE,
                            index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE
                        ]
                    }
                }
            },
            {
                label: 'Share username/password across all users',
                name: 'authConfig.useFixedPasswordCreds',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CHECKBOX,
                tooltip: {
                    markdownText: `Username/password credentials to use when connecting. If not set, users will be prompted for their credentials.`
                },
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_PASSWORD]
                    }
                },
                initialValue: false
            },
            {
                label: 'Client authentication',
                name: 'authConfig.clientAuthMethod',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.DROPDOWN,
                initialValue: ClientAuthMethod.POST,
                options: [
                    {
                        displayName: 'Send client credentials in body',
                        key: ClientAuthMethod.POST,
                        value: ClientAuthMethod.POST
                    },
                    {
                        displayName: 'Send as Basic Auth header',
                        key: ClientAuthMethod.BASIC,
                        value: ClientAuthMethod.BASIC
                    }
                ],
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            },
            {
                label: 'Send state parameter',
                name: 'authConfig.sendOAuthState',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CHECKBOX,
                tooltip: {
                    markdownText: `Opaque state value will be sent to prevent cross-site request forgery.`
                },
                initialValue: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            },
            {
                label: 'Username',
                name: 'authConfig.username',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                placeholder: `username`,
                singleLine: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_PASSWORD],
                        'authConfig.useFixedPasswordCreds': ['true']
                    }
                }
            },
            {
                label: 'Password',
                name: 'authConfig.password',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                placeholder: `password`,
                dataType: index_js_1.InputDataType.PASSWORD,
                singleLine: false,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_PASSWORD],
                        'authConfig.useFixedPasswordCreds': ['true']
                    }
                }
            },
            {
                label: '',
                messageTemplate: `Send your token to requests by adding it to a header or parameter using **\`{{ oauth.token }}\`**.
          Learn more in our docs on [using OAuth2.0 in Superblocks](https://docs.superblocks.com/integrations/auth/oauth-20).`,
                name: 'OAuth2PasswordAlert',
                startVersion,
                componentType: index_js_1.FormComponentType.ALERT,
                display: {
                    show: {
                        authType: [
                            index_js_1.IntegrationAuthType.OAUTH2_PASSWORD,
                            index_js_1.IntegrationAuthType.OAUTH2_CLIENT_CREDS,
                            index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT,
                            index_js_1.IntegrationAuthType.OAUTH2_CODE,
                            index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE
                        ]
                    }
                }
            },
            {
                label: '',
                messageTemplate: `Your identity provider token from SSO login will be available as **\`{{ oauth.token }}\`**. Add it to a header or parameter.
          This method requires an interactive session — it cannot be used in Workflows or Scheduled Jobs.`,
                name: 'IdpTokenPassthroughAlert',
                startVersion,
                componentType: index_js_1.FormComponentType.ALERT,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_IDP_TOKEN_PASSTHROUGH]
                    }
                }
            }
        ], fieldNamesToHide);
    }
    if (enabledMethods.oauth2BringYourOwn) {
        addField(authFields, [
            {
                label: 'Callback URL',
                name: 'oauth-callback-alert',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                disabled: true,
                immutable: true,
                initialValue: `<%= origin %>/${index_js_1.OAUTH_CALLBACK_PATH}`,
                tooltip: {
                    markdownText: `This is where users will be redirected after authorization. Add this to your application's list of allowed callback URLs.`
                },
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                },
                enableCopy: true,
                singleLine: false
            },
            {
                label: 'Access token URL',
                name: 'authConfig.tokenUrl',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                hidden: true,
                initialValue: enabledMethods.oauth2BringYourOwn?.tokenUrl
            },
            {
                label: 'Authorization URL',
                name: 'authConfig.authorizationUrl',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                hidden: true,
                initialValue: enabledMethods.oauth2BringYourOwn?.authorizationUrl
            },
            {
                label: 'Revoke token URL',
                name: 'authConfig.revokeTokenUrl',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                hidden: true,
                initialValue: enabledMethods?.oauth2BringYourOwn?.revokeTokenUrl
            },
            {
                label: 'User info URL',
                name: 'authConfig.userInfoUrl',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                hidden: true,
                initialValue: enabledMethods?.oauth2BringYourOwn?.userInfoUrl
            },
            {
                label: 'Server-side token refresh',
                name: 'authConfig.refreshTokenFromServer',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CHECKBOX,
                hidden: true,
                initialValue: false
            },
            {
                label: 'Client ID',
                name: 'authConfig.clientId',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                placeholder: `Client ID`,
                rules: [{ required: true, message: 'Client ID is required' }],
                tooltip: {
                    markdownText: `The client identifier issued to the client during the application registration process.`
                },
                singleLine: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            },
            {
                label: 'Client secret',
                name: 'authConfig.clientSecret',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                rules: [{ required: true, message: 'Client secret is required' }],
                placeholder: `Client Secret`,
                dataType: index_js_1.InputDataType.PASSWORD,
                tooltip: {
                    markdownText: `The client secret issues to the client during the application registration process.`
                },
                singleLine: false,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            },
            {
                label: 'Audience',
                name: 'authConfig.audience',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                tooltip: {
                    markdownText: `The intended recipient of the token, most likely a resource server.`
                },
                singleLine: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            },
            {
                label: 'Scope',
                name: 'authConfig.scope',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                placeholder: `e.g. openid email read:org`,
                tooltip: {
                    markdownText: `The scope of access request. It may have multiple space-separated values.`
                },
                singleLine: true,
                initialValue: enabledMethods.oauth2BringYourOwn?.defaultScope ?? enabledMethods.oauth2SuperblocksClient?.defaultScope,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            },
            {
                label: 'Client authentication',
                name: 'authConfig.clientAuthMethod',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                hidden: true,
                initialValue: enabledMethods.oauth2BringYourOwn?.clientAuthMethod ?? ClientAuthMethod.POST
            },
            {
                label: 'Send state parameter',
                name: 'authConfig.sendOAuthState',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CHECKBOX,
                initialValue: true,
                tooltip: {
                    markdownText: `Opaque state value will be sent to prevent cross-site request forgery.`
                },
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            },
            {
                label: 'Share access token across all users',
                name: 'authConfig.tokenScope',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CHECKBOX,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                },
                mapBooleansTo: {
                    true: index_js_1.TokenScope.DATASOURCE,
                    false: index_js_1.TokenScope.USER
                },
                initialValue: index_js_1.TokenScope.DATASOURCE,
                validateReduxPath: {
                    true: {
                        selector: 'selectHasConnectedTokens',
                        validValue: true,
                        errorMessage: `You must connect to ${pluginName} before you can share access token`
                    }
                }
            }
        ], fieldNamesToHide);
    }
    if (enabledMethods.oauth2SuperblocksClient) {
        addField(authFields, [
            {
                label: 'Callback URL',
                name: 'oauth-callback-alert',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                disabled: true,
                immutable: true,
                initialValue: `<%= origin %>/${index_js_1.OAUTH_CALLBACK_PATH}`,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                },
                enableCopy: true,
                singleLine: false
            },
            {
                label: 'Access token URL',
                name: 'authConfig.tokenUrl',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                hidden: true,
                initialValue: enabledMethods?.oauth2SuperblocksClient?.tokenUrl
            },
            {
                label: 'Authorization URL',
                name: 'authConfig.authorizationUrl',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                hidden: true,
                initialValue: enabledMethods?.oauth2SuperblocksClient?.authorizationUrl
            },
            {
                label: 'Revoke token URL',
                name: 'authConfig.revokeTokenUrl',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                hidden: true,
                initialValue: enabledMethods?.oauth2SuperblocksClient?.revokeTokenUrl
            },
            {
                label: 'User info URL',
                name: 'authConfig.userInfoUrl',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                hidden: true,
                initialValue: enabledMethods?.oauth2SuperblocksClient?.userInfoUrl
            },
            {
                label: 'Server-side token refresh',
                name: 'authConfig.refreshTokenFromServer',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CHECKBOX,
                hidden: true,
                initialValue: true
            },
            {
                label: 'Client ID',
                name: 'authConfig.clientId',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                placeholder: `Client ID`,
                rules: [{ required: true, message: 'Client ID is required' }],
                tooltip: {
                    markdownText: `A public identifier used to identify this client
    to the authorization/token servers.`
                },
                singleLine: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                },
                hidden: true,
                initialValue: enabledMethods?.oauth2SuperblocksClient?.clientId
            },
            {
                label: 'Audience',
                name: 'authConfig.audience',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                tooltip: {
                    markdownText: `The intended recipient of the token, most likely a resource server.`
                },
                singleLine: true,
                hidden: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            },
            {
                label: 'Scope',
                name: 'authConfig.scope',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.INPUT_TEXT,
                placeholder: `e.g. openid email read:org`,
                tooltip: {
                    markdownText: `The scope of access request. It may have multiple space-separated values.`
                },
                singleLine: true,
                hidden: true,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE, index_js_1.GoogleSheetsAuthType.SERVICE_ACCOUNT]
                    }
                }
            },
            {
                label: 'Share access token across all users',
                name: 'authConfig.tokenScope',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.CHECKBOX,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                },
                mapBooleansTo: {
                    true: index_js_1.TokenScope.DATASOURCE,
                    false: index_js_1.TokenScope.USER
                },
                initialValue: index_js_1.TokenScope.DATASOURCE,
                validateReduxPath: {
                    true: {
                        selector: 'selectHasConnectedTokens',
                        validValue: true,
                        errorMessage: `You must connect to ${pluginName} before you can share access token`
                    }
                }
            }
        ], fieldNamesToHide);
    }
    if (enabledMethods.oauth2SuperblocksClient || enabledMethods.oauth2BringYourOwn) {
        addField(authFields, [
            {
                label: '',
                name: 'OAuth2ConnectedAlert',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.ALERT,
                messageTemplate: `<%= datasourceMeta?.metadata?.connectedUserTokens?.[configurationId]?.[0]
              ? 'You are connected to ${pluginName}'
              : undefined %>` +
                    `<%= datasourceMeta?.metadata?.connectedUserTokens?.[configurationId]?.[0]?.tokenMetadata?.email
              ? ' as ' + datasourceMeta?.metadata?.connectedUserTokens?.[configurationId]?.[0]?.tokenMetadata?.email + '!'
              : datasourceMeta?.metadata?.connectedUserTokens?.[configurationId]?.[0]
              ? '!'
              : undefined
            %>`,
                type: 'success',
                showIcon: true
            }
        ], fieldNamesToHide);
    }
    formSections.push({
        name: 'auth',
        borderThreshold: 1,
        items: authFields
    });
    const authButtons = [];
    if (enabledMethods.oauth2BringYourOwn || enabledMethods.oauth2SuperblocksClient) {
        const authorizationExtraParams = enabledMethods?.oauth2BringYourOwn?.authorizationExtraParams || enabledMethods.oauth2SuperblocksClient?.authorizationExtraParams;
        const iconUrl = enabledMethods?.oauth2BringYourOwn?.iconUrl || enabledMethods.oauth2SuperblocksClient?.iconUrl;
        addField(authButtons, [
            {
                label: `Connect to ${pluginName}`,
                name: 'oauth-connect-button',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.BUTTON,
                buttonType: 'connectOAuth',
                valuesFromContext: [
                    'authType',
                    'authConfig.scope',
                    'authConfig.clientId',
                    'authConfig.tokenScope',
                    'authConfig.userInfoUrl',
                    'authConfig.clientSecret',
                    'authConfig.tokenUrl',
                    'authConfig.authorizationUrl',
                    'authConfig.refreshTokenFromServer',
                    'authConfig.clientAuthMethod',
                    'dynamicWorkflowConfiguration.enabled',
                    'dynamicWorkflowConfiguration.workflowId'
                ],
                extraValues: {
                    pluginId: pluginId,
                    ...authorizationExtraParams
                },
                iconUrl,
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                },
                dependencies: ['authConfig.tokenScope']
            },
            {
                label: `Revoke token`,
                name: 'oauth-revoke-shared-tokens-button',
                startVersion: startVersion,
                componentType: index_js_1.FormComponentType.BUTTON,
                buttonType: 'revokeOAuthTokens',
                valuesFromContext: [
                    'authType',
                    'authConfig.scope',
                    'authConfig.clientId',
                    'authConfig.tokenScope',
                    'authConfig.userInfoUrl',
                    'authConfig.clientSecret',
                    'authConfig.tokenUrl',
                    'authConfig.authorizationUrl',
                    'authConfig.refreshTokenFromServer',
                    'authConfig.revokeTokenUrl'
                ],
                display: {
                    show: {
                        authType: [index_js_1.IntegrationAuthType.OAUTH2_CODE]
                    }
                }
            }
        ], fieldNamesToHide);
    }
    formSections.push({
        name: 'authButtons',
        items: [
            {
                gridCss: {
                    gridTemplateColumns: 'auto 1fr',
                    gridTemplateGap: 8
                },
                rowItems: authButtons
            }
        ]
    });
    // Apply endVersion to all items so callers can cap the version range of the entire auth section.
    if (endVersion) {
        for (const section of formSections) {
            for (const item of section.items) {
                if ('startVersion' in item) {
                    item.endVersion = item.endVersion ?? endVersion;
                }
                if ('rowItems' in item) {
                    for (const rowItem of item.rowItems) {
                        rowItem.endVersion = rowItem.endVersion ?? endVersion;
                    }
                }
            }
        }
    }
    return formSections;
};
exports.authSections = authSections;
function apiKeyMarkdownText(pluginId) {
    return `Specify the header key ${pluginId === index_js_1.ExtendedIntegrationPluginId.GRAPHQL ? '' : 'or the query parameter'} used to pass the API key`;
}
function apiKeyAuthOptions(pluginId) {
    const options = [
        {
            displayName: 'Header',
            key: index_js_1.ApiKeyMethod.HEADER,
            value: index_js_1.ApiKeyMethod.HEADER
        }
    ];
    if (pluginId === index_js_1.ExtendedIntegrationPluginId.REST_API) {
        options.push({
            displayName: 'Query parameter',
            key: index_js_1.ApiKeyMethod.QUERY_PARAM,
            value: index_js_1.ApiKeyMethod.QUERY_PARAM
        });
    }
    return options;
}
// This generates the dropdown set of authentication methods available
// for the given plugin/integration.
function authTypeOptions({ enabledMethods, allowNone = true, isProto = false, apiKeyFormDisplayName }) {
    const options = allowNone
        ? [
            {
                displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.NONE),
                value: index_js_1.IntegrationAuthType.NONE,
                key: index_js_1.IntegrationAuthType.NONE
            }
        ]
        : [];
    if (enabledMethods.basic) {
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.BASIC),
            value: index_js_1.IntegrationAuthType.BASIC,
            key: index_js_1.IntegrationAuthType.BASIC
        });
    }
    if (enabledMethods.bearer) {
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.BEARER),
            value: index_js_1.IntegrationAuthType.BEARER,
            key: index_js_1.IntegrationAuthType.BEARER
        });
    }
    if (enabledMethods.tokenPrefixed) {
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.TOKEN_PREFIXED),
            value: index_js_1.IntegrationAuthType.TOKEN_PREFIXED,
            key: index_js_1.IntegrationAuthType.TOKEN_PREFIXED
        });
    }
    if (enabledMethods.apiKeyForm) {
        options.push({
            displayName: apiKeyFormDisplayName ?? (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.API_KEY_FORM),
            value: index_js_1.IntegrationAuthType.API_KEY_FORM,
            key: index_js_1.IntegrationAuthType.API_KEY_FORM
        });
    }
    if (enabledMethods.apiKey) {
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.API_KEY),
            value: index_js_1.IntegrationAuthType.API_KEY,
            key: index_js_1.IntegrationAuthType.API_KEY
        });
    }
    if (enabledMethods.firebase) {
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.FIREBASE),
            value: index_js_1.IntegrationAuthType.FIREBASE,
            key: index_js_1.IntegrationAuthType.FIREBASE
        });
    }
    if (enabledMethods.oauth) {
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.OAUTH2_CLIENT_CREDS),
            value: index_js_1.IntegrationAuthType.OAUTH2_CLIENT_CREDS,
            key: index_js_1.IntegrationAuthType.OAUTH2_CLIENT_CREDS
        });
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.OAUTH2_CODE),
            value: index_js_1.IntegrationAuthType.OAUTH2_CODE,
            key: index_js_1.IntegrationAuthType.OAUTH2_CODE
        });
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT),
            value: index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT,
            key: index_js_1.IntegrationAuthType.OAUTH2_IMPLICIT
        });
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.OAUTH2_PASSWORD),
            value: index_js_1.IntegrationAuthType.OAUTH2_PASSWORD,
            key: index_js_1.IntegrationAuthType.OAUTH2_PASSWORD
        });
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE),
            value: index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE,
            key: index_js_1.IntegrationAuthType.OAUTH2_TOKEN_EXCHANGE
        });
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.IntegrationAuthType.OAUTH2_IDP_TOKEN_PASSTHROUGH),
            value: index_js_1.IntegrationAuthType.OAUTH2_IDP_TOKEN_PASSTHROUGH,
            key: index_js_1.IntegrationAuthType.OAUTH2_IDP_TOKEN_PASSTHROUGH
        });
    }
    if (enabledMethods.oauth2BringYourOwn) {
        options.push({
            displayName: `OAuth2.0 - Authorization Code`,
            value: index_js_1.IntegrationAuthType.OAUTH2_CODE,
            key: index_js_1.IntegrationAuthType.OAUTH2_CODE
        });
    }
    // following is only used by proto based plugins
    // the keys are proto oneof case options
    if (enabledMethods.passwordGrantFlow) {
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.NewAuthType.OAUTH2_PASSWORD_GRANT_FLOW),
            value: index_js_1.NewAuthType.OAUTH2_PASSWORD_GRANT_FLOW,
            key: index_js_1.NewAuthType.OAUTH2_PASSWORD_GRANT_FLOW
        });
    }
    if (enabledMethods.clientCredentialsFlow) {
        options.push({
            displayName: (0, index_js_1.getDisplayName)(index_js_1.NewAuthType.OAUTH2_CLIENT_CREDS_FLOW),
            value: index_js_1.NewAuthType.OAUTH2_CLIENT_CREDS_FLOW,
            key: index_js_1.NewAuthType.OAUTH2_CLIENT_CREDS_FLOW
        });
    }
    return options;
}
function addField(authFields, fieldsToAdd, fieldNamesToHide) {
    for (const field of fieldsToAdd) {
        authFields.push({ ...field, hidden: field.hidden || fieldNamesToHide.includes(field.name) });
    }
}
const BASE_OAUTH_BINDING_ALERT = {
    label: '',
    messageTemplate: `Bindings such as \`{{ Env.client_secret }}\` aren't supported for this auth type. Please explicitly set configuration values.`,
    name: 'oauth-binding-alert',
    componentType: index_js_1.FormComponentType.ALERT,
    type: 'warning'
};
const BASE_OAUTH_BINDING_ALERT_AUTH_CODE = {
    label: '',
    messageTemplate: `Bindings such as \`{{ Env.client_secret }}\` are only supported for the "Client secret" field for this auth type. Please explicitly set configuration values for the remaining fields.`,
    name: 'oauth-binding-alert',
    componentType: index_js_1.FormComponentType.ALERT,
    type: 'warning'
};
exports.BASE_SUBJECT_TOKEN_SOURCE = {
    label: 'Subject token source',
    name: 'authConfig.subjectTokenSource',
    componentType: index_js_1.FormComponentType.DROPDOWN,
    tooltip: {
        markdownText: `The source of the subject token to be used in the token exchange. The Login Identity Provider option sends the token granted to the current user by an identity provider like Okta.`
    },
    options: [
        {
            displayName: 'Login Identity Provider',
            value: 'SUBJECT_TOKEN_SOURCE_LOGIN_IDENTITY_PROVIDER',
            key: 'SUBJECT_TOKEN_SOURCE_LOGIN_IDENTITY_PROVIDER'
        },
        {
            displayName: 'Static Token',
            value: 'SUBJECT_TOKEN_SOURCE_STATIC_TOKEN',
            key: 'SUBJECT_TOKEN_SOURCE_STATIC_TOKEN'
        }
    ],
    initialValue: 'SUBJECT_TOKEN_SOURCE_LOGIN_IDENTITY_PROVIDER',
    singleLine: false
};
exports.BASE_SUBJECT_TOKEN_TYPE = {
    label: 'Subject token type',
    name: 'authConfig.subjectTokenType',
    componentType: index_js_1.FormComponentType.INPUT_TEXT,
    tooltip: {
        markdownText: 'The type of the subject token to be used in the token exchange.'
    },
    placeholder: 'urn:ietf:params:oauth:token-type:access_token',
    singleLine: false
};
exports.BASE_SUBJECT_TOKEN_STATIC_TOKEN = {
    label: 'Static subject token',
    name: 'authConfig.subjectTokenSourceStaticToken',
    componentType: index_js_1.FormComponentType.INPUT_TEXT,
    dataType: index_js_1.InputDataType.PASSWORD,
    tooltip: {
        markdownText: `A static token to be used in the token exchange. This option can be leveraged for testing purposes.`
    },
    singleLine: false
};
exports.BASE_TOKEN_URL = {
    label: 'Token URL',
    name: 'authConfig.tokenUrl',
    componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
    rules: [{ required: true, message: 'Token URL is required' }],
    tooltip: {
        markdownText: `The endpoint for authorization server. This is used to get the access token.`
    },
    singleLine: true,
    placeholder: `https://example.com/login/oauth/token`
};
exports.BASE_CLIENT_ID = {
    label: 'Client ID',
    name: 'authConfig.clientId',
    componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
    placeholder: `Client ID`,
    rules: [{ required: true, message: 'Client ID is required' }],
    tooltip: {
        markdownText: `The ID issued to the client during client registration.`
    },
    singleLine: true
};
exports.BASE_CLIENT_SECRET = {
    label: 'Client secret',
    name: 'authConfig.clientSecret',
    componentType: index_js_1.FormComponentType.INPUT_TEXT,
    rules: [{ required: true, message: 'Client secret is required' }],
    placeholder: `Client Secret`,
    dataType: index_js_1.InputDataType.PASSWORD,
    tooltip: {
        markdownText: `The secret issued to the client during client registration.`
    },
    singleLine: false
};
exports.BASE_AUDIENCE = {
    // TODO: Ideally hide behind an advanced setting with audience.
    label: 'Audience',
    name: 'authConfig.audience',
    componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
    tooltip: {
        markdownText: `The intended recipient of the token, most likely a resource server.`
    },
    singleLine: true
};
exports.BASE_SCOPE = {
    label: 'Scope',
    name: 'authConfig.scope',
    componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
    placeholder: `e.g. openid email read:org`,
    tooltip: {
        markdownText: `The scope of access request. It may have multiple space-separated values.`
    },
    singleLine: true
};
//# sourceMappingURL=auth.js.map