public static async ValueTask <HttpClient> Create(string apiKey, string apiSecret)
        {
            Log.Information("creating fiskaly client...");
            var authenticationHandler = new AuthenticationHandler(new HttpClientHandler(), apiKey, apiSecret);
            await authenticationHandler.Start().ConfigureAwait(false);

            var pollyHandler = new PollyHandler(authenticationHandler)
            {
                Policy = PollyPolicyFactory.CreateGeneralPolicy()
            };
            var        transactionHandler           = new TransactionHandler(pollyHandler);
            var        requestUriEnforcementHandler = new RequestUriEnforcementHandler(transactionHandler);
            HttpClient client = new HttpClient(requestUriEnforcementHandler)
            {
                BaseAddress = new Uri(Constants.BaseAddress),
                Timeout     = Timeout.InfiniteTimeSpan
            };

            return(client);
        }
Ejemplo n.º 2
0
        internal AuthenticationHandler(HttpMessageHandler handler, string apiKey, string apiSecret)
        {
            Log.Information("initializing authentication handler...");
            base.InnerHandler = handler;
            _apiKey           = apiKey;
            _apiSecret        = apiSecret;

            var httpClientHandler = new HttpClientHandler();
            var pollyHandler      = new PollyHandler(httpClientHandler)
            {
                Policy = PollyPolicyFactory.CreateAuthPolicy()
            };

            _authenticationClient = new HttpClient(pollyHandler)
            {
                BaseAddress = new Uri(Constants.BaseAddress),
                Timeout     = Timeout.InfiniteTimeSpan
            };

            _authenticationContext = new AuthenticationContext();
        }