private static void Authenticate()
 {
     if (String.IsNullOrEmpty(TokenWallet.GetCurrentTokens().Token))
     {
         Console.WriteLine("Richiesta di un nuovo token");
         Login(Constants.REST_MULTIDIALOGO_STAGE_USERNAME, Constants.REST_MULTIDIALOGO_STAGE_PASSWORD).Wait();
     }
     else
     {
         Console.WriteLine("Riutilizzo token salvato " + TokenWallet.GetCurrentTokens().Token);
     }
 }
        private static async Task <HttpResponseMessage> LoginRefresh(string username)
        {
            string token = TokenWallet.GetCurrentTokens().RefreshToken;
            string json  = RefreshTokenRequest.CreateRefreshTokenRequestAsJson(username, token);
            string url   = Constants.REST_MULTIDIALOGO_STAGE_HOST + "/users/login/refresh";

            HttpResponseMessage res = await http.SendAsync(Utils.CreateRequest(url, token, Utils.CreateStringContent(json), "Post"));

            if (res.IsSuccessStatusCode)
            {
                string responseContent = await res.Content.ReadAsStringAsync();

                AuthResponse authResponse = JsonConvert.DeserializeObject <AuthResponse>(responseContent);
                Console.WriteLine("Refresh token ricevuto: " + authResponse.GetTokenResponse().RefreshToken);
                StoreTokens(authResponse);
            }
            return(res);
        }
Beispiel #3
0
 public static HttpRequestMessage CreateCurrTokenRequest(string url, string json, string method)
 {
     return(CreateRequest(url, TokenWallet.GetCurrentTokens().Token, CreateStringContent(json), method));
 }
 private static void StoreTokens(AuthResponse authResponse)
 {
     TokenWallet.WriteTokens(authResponse.GetTokenResponse());
 }
        static void Main(string[] args)
        {
            http = Utils.CreateHttpClient();
            TokenWallet.ReadTokens();

            while (!done)
            {
                Menu();

                int choice = Utils.GetChoice();

                if (choice <= 0)
                {
                    done = true;
                    continue;
                }

                Authenticate();

                switch (choice)
                {
                case 1:
                    Scenario_1().Wait();
                    break;

                case 2:
                    Scenario_2().Wait();
                    break;

                case 3:
                    Scenario_3().Wait();
                    break;

                case 4:
                    Scenario_4().Wait();
                    break;

                case 5:
                    Scenario_5().Wait();
                    break;

                case 6:
                    Scenario_6().Wait();
                    break;

                case 7:
                    Scenario_7().Wait();
                    break;

                case 8:
                    Scenario_8().Wait();
                    break;

                case 9:
                    Scenario_9().Wait();
                    break;

                default:
                    Console.WriteLine("Scelta errata");
                    break;
                }
            }
        }