internal static OktaConnectionContext GetConnectionContext(KeyedCollection <string, ConfigParameter> configParameters)
        {
            ProxyConfiguration proxyConfig = null;

            if (!string.IsNullOrWhiteSpace(OktaMAConfigSection.Configuration.ProxyUrl))
            {
                proxyConfig = new ProxyConfiguration()
                {
                    Host = OktaMAConfigSection.Configuration.ProxyUrl
                };
                logger.Info($"Using proxy host {proxyConfig.Host}");
            }

            logger.Info($"Setting up connection to {configParameters[ConfigParameterNames.TenantUrl].Value}");

            System.Net.ServicePointManager.DefaultConnectionLimit = OktaMAConfigSection.Configuration.ConnectionLimit;
            GlobalSettings.ExportThreadCount = OktaMAConfigSection.Configuration.ExportThreads;

            NLog.Extensions.Logging.NLogLoggerProvider f = new NLog.Extensions.Logging.NLogLoggerProvider();
            ILogger nlogger = f.CreateLogger("ext-logger");

            OktaClientConfiguration oktaConfig = new OktaClientConfiguration
            {
                OktaDomain        = configParameters[ConfigParameterNames.TenantUrl].Value,
                Token             = configParameters[ConfigParameterNames.ApiKey].SecureValue.ConvertToUnsecureString(),
                Proxy             = proxyConfig,
                ConnectionTimeout = OktaMAConfigSection.Configuration.HttpClientTimeout,
                MaxRetries        = 8,
            };

            HttpClient httpClient;

            if (OktaMAConfigSection.Configuration.HttpDebugEnabled)
            {
                logger.Warn("WARNING: HTTPS Debugging enabled. Service certificate validation is disabled");

                httpClient = OktaConnectionContext.CreateDebugHttpClient(nlogger, oktaConfig);
            }
            else
            {
                httpClient = DefaultHttpClient.Create(oktaConfig.ConnectionTimeout, proxyConfig, nlogger);
            }

            return(new OktaConnectionContext()
            {
                Client = new OktaClient(oktaConfig, httpClient, nlogger, new DefaultRetryStrategy(oktaConfig.MaxRetries ?? 8, 0, 1))
            });
        }
Esempio n. 2
0
 public object GetConnectionContext(KeyedCollection <string, ConfigParameter> configParameters, ConnectionContextOperationType contextOperationType)
 {
     return(OktaConnectionContext.GetConnectionContext(configParameters));
 }