public void BuildPKCEAuthUrl()
        {
            using (var handler = new HttpClientHandler {
                UseCookies = false, AllowAutoRedirect = false
            })
                using (var httpClient = new HttpClient(handler)) // httpClient lifetime is handled by caller - client should be kept for duration of SaxoClient lifetime
                {
                    var config = new SaxoClientOptions
                    {
                        // Set the appkey to whatever value is stores in the secrets manager
                        AppKey = _configuration["SaxoClient:AppKey"],
                    };

                    Assert.NotEmpty(config.AppKey);

                    using (var saxoClient = new SaxoClient(
                               _loggerFactory.CreateLogger <SaxoClient>(),
                               Options.Create(config),
                               httpClient))
                    {
                        var authUri = saxoClient.GetPKCEAuthUrl();
                        _logger.LogInformation("Got the authentication Uri: {uri}", authUri);

                        Assert.StartsWith(config.AuthenticationUrl, authUri);
                        Assert.Contains(config.AppKey, authUri);
                        Assert.Contains(saxoClient.CodeVerifier, authUri);
                        Assert.Contains("S256", authUri);
                        Assert.Contains(Uri.EscapeDataString(saxoClient.RedirectUrl), authUri);
                    }
                }
        }
Esempio n. 2
0
        static void Init()
        {
            // the type specified here is just so the secrets library can
            // find the UserSecretId we added in the csproj file, and the secrets defined for it
            var builder = new ConfigurationBuilder()
                          .AddUserSecrets <Program>();

            _configuration = builder.Build();

            var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole(options => { options.DisableColors = false; options.IncludeScopes = false; }).SetMinimumLevel(LogLevel.Debug));

            _logger = loggerFactory.CreateLogger <Program>();

            _saxoConfig = new SaxoClientOptions
            {
                // Set the appkey to whatever value is stores in the secrets manager
                AppKey = _configuration["SaxoClient:AppKey"],
                AppUrl = _configuration["SaxoClient:AppName"],
            };

            _handler = new HttpClientHandler {
                UseCookies = false, AllowAutoRedirect = false
            };
            _httpClient = new HttpClient(_handler);
            _saxoClient = new SaxoClient(
                loggerFactory.CreateLogger <SaxoClient>(),
                Options.Create(_saxoConfig),
                _httpClient);
        }
Esempio n. 3
0
        static void Cleanup()
        {
            if (_saxoClient != null)
            {
                _saxoClient.Dispose();
                _saxoClient = null;
            }
            if (_httpClient != null)
            {
                _httpClient.Dispose();
                _httpClient = null;
            }
            if (_handler != null)
            {
                _handler.Dispose();
                _handler = null;
            }

            _cts.Dispose();
        }
        public void CreateConnectDispose()
        {
            using (var handler = new HttpClientHandler {
                UseCookies = false, AllowAutoRedirect = false
            })
                using (var httpClient = new HttpClient(handler)) // httpClient lifetime is handled by caller - client should be kept for duration of SaxoClient lifetime
                {
                    var config = new SaxoClientOptions
                    {
                        // Set the appkey to whatever value is stores in the secrets manager
                        AppKey = _configuration["SaxoClient:AppKey"],
                    };

                    Assert.NotEmpty(config.AppKey);

                    using (var saxoClient = new SaxoClient(
                               _loggerFactory.CreateLogger <SaxoClient>(),
                               Options.Create(config),
                               httpClient))
                    {
                    }
                }
        }