public static async Task RunRefreshAsync(TokenResponse response) { string refresh_token = response.RefreshToken; response = await RefreshTokenAsync(refresh_token); // Get the resource data using the new tokens... await ResourceDataClient.GetDataAndDisplayInConsoleAsync(response.AccessToken); ShowResponse(response); }
static void Main(string[] args) { while (true) { try { string action = QueryAction(); if (action == "Q") { break; } else if (action == "1") { response = IdentityServer4Client.LoginAsync("damienbod", "damienbod").Result; Console.WriteLine("GOT TOKENS FROM IDENTITYSERVER4: {0}", response.AccessToken); } else if (action == "2") { ResourceDataClient.GetDataAndDisplayInConsoleAsync(response.AccessToken).Wait(); } else if (action == "3") {//Run an loop which gets refreshes the token every 3000 milliseconds IdentityServer4Client.RunRefreshAsync(response).Wait(); } else if (action == "4") {//Run an loop which gets refreshes the token every 3000 milliseconds IdentityServer4Client.RunRefreshAsync(response, 3000).Wait(); } else if (action == "C") { Console.Clear(); } else { Console.Write("Unknow Command!!\n"); } } catch (System.Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error: " + e.Message); Console.ForegroundColor = ConsoleColor.White; } } Console.WriteLine("Program shutdown."); }
public static async Task RunRefreshAsync(TokenResponse response, int milliseconds) { var refresh_token = response.RefreshToken; while (true) { response = await RefreshTokenAsync(refresh_token); // Get the resource data using the new tokens... await ResourceDataClient.GetDataAndDisplayInConsoleAsync(response.AccessToken); if (response.RefreshToken != refresh_token) { ShowResponse(response); refresh_token = response.RefreshToken; } Task.Delay(milliseconds).Wait(); } }