Beispiel #1
0
        public async Task Logout()
        {
            KiteAccessTokenResponseRoot kiteAccessTokenResponseRoot = null;
            bool cacheFetchResult = this._cache.TryGetValue <KiteAccessTokenResponseRoot>("kite_access_token", out kiteAccessTokenResponseRoot);

            if ((kiteAccessTokenResponseRoot != null) && cacheFetchResult)
            {
                this._cache.Remove("kite_access_token");
                var param = new Dictionary <string, dynamic>();
                CommonFunctions.AddIfNotNull(param, "api_key", this._configuration.GetValue <string>("kiteApiKey"));
                CommonFunctions.AddIfNotNull(param, "access_token", (string)kiteAccessTokenResponseRoot.data.access_token);
                string encodedParmas = string.Empty;
                foreach (KeyValuePair <string, dynamic> keyValuePair in param)
                {
                    if (string.IsNullOrEmpty(encodedParmas))
                    {
                        encodedParmas = CommonFunctions.BuildParam(keyValuePair.Key, keyValuePair.Value);
                    }
                    else
                    {
                        encodedParmas = encodedParmas + "&" + CommonFunctions.BuildParam(keyValuePair.Key, keyValuePair.Value);
                    }
                }

                string kiteLogoutUrl = $"{this._configuration.GetValue<string>("kiteApiBaseUrl")}{this._configuration.GetValue<string>("kiteAccessTokenUrl")}?{encodedParmas}";
                this._httpClient.DefaultRequestHeaders.Add("X-Kite-Version", "3");
                HttpResponseMessage httpResponseMessage = await this._httpClient.DeleteAsync(kiteLogoutUrl);

                if (httpResponseMessage.IsSuccessStatusCode)
                {
                    this._logger.LogInformation("Logout from Kite API Successful.");
                }
                else
                {
                    this._logger.LogError("Logout from Kite API Unsuccessful.");
                }
            }
        }