public static void Run()
        {
            Console.WriteLine("Enter to run Resource Owner Credentials demo.");

            #region initial request

            // get an access token for the username and password
            var state = GetAccessToken();

            var tokenexpires = state.AccessTokenExpirationUtc;
            var token        = state.AccessToken;
            var refresh      = state.RefreshToken;

            Console.WriteLine("Expires = {0}", tokenexpires);
            Console.WriteLine();
            Console.WriteLine("Token = {0}", token);
            Console.WriteLine();
            Console.WriteLine("Refresh Token = {0}", refresh);
            Console.WriteLine();

            #region sych request

            Console.WriteLine("");
            Console.WriteLine("Hit a key to make a sychronous request.");
            Console.WriteLine("");
            Console.ReadKey();

            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(API_ENDPOINT);
            myReq.Headers.Add("Authorization", "Bearer " + token);
            WebResponse            myReqResp       = myReq.GetResponse();
            System.IO.StreamReader myReqRespStream = new System.IO.StreamReader(myReqResp.GetResponseStream());
            Console.WriteLine(myReqRespStream.ReadToEnd());
            Console.WriteLine("");
            Console.WriteLine("Request Complete.");
            Console.ReadKey();
            Console.WriteLine("");

            #endregion



            // get a reference to the access token
            var httpClient = new OAuthHttpClient(token)
            {
                BaseAddress = new Uri(API_ENDPOINT)
            };


            Console.WriteLine("Calling web api...");
            Console.WriteLine("...");

            // make the request
            var response = httpClient.GetAsync("").Result;
            Console.WriteLine("Got Response");

            // if ok write the result
            if (response.StatusCode == HttpStatusCode.OK)
            {
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                Console.WriteLine("Error");
            }

            Console.WriteLine();
            /*  */
            #endregion

            #region refreshing

            Console.WriteLine("Refreshing token ...");

            // first update the state to get a new token
            state = GetAccessToken(state.RefreshToken);

            tokenexpires = state.AccessTokenExpirationUtc;
            token        = state.AccessToken;
            refresh      = state.RefreshToken;

            Console.WriteLine("Refresh Expires = {0}", tokenexpires);
            Console.WriteLine();
            Console.WriteLine("Token = {0}", token);
            Console.WriteLine();

            httpClient = new OAuthHttpClient(token)
            {
                BaseAddress = new Uri(API_ENDPOINT)
            };


            Console.WriteLine("Enter to call web api...");
            Console.WriteLine("...");

            // make the request
            response = httpClient.GetAsync("").Result;
            Console.WriteLine("Got Response");

            // if ok write the result
            if (response.StatusCode == HttpStatusCode.OK)
            {
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                Console.WriteLine("Error");
            }

            Console.WriteLine();
            Console.WriteLine("Finished calling API with refresh token");
            Console.WriteLine();
            /**/
            #endregion

            Console.WriteLine();
            Console.WriteLine("Done");
            Console.ReadLine();
        }
        public static void Run()
        {
            Console.WriteLine("Enter to run Resource Owner Credentials demo.");

            #region initial request

            // get an access token for the username and password
            var state = GetAccessToken();

            var tokenexpires = state.AccessTokenExpirationUtc;
            var token = state.AccessToken;
            var refresh = state.RefreshToken;

            Console.WriteLine("Expires = {0}", tokenexpires);
            Console.WriteLine();
            Console.WriteLine("Token = {0}", token);
            Console.WriteLine();
            Console.WriteLine("Refresh Token = {0}", refresh);
            Console.WriteLine();

            #region sych request

            Console.WriteLine("");
            Console.WriteLine("Hit a key to make a sychronous request.");
            Console.WriteLine("");
            Console.ReadKey();

            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(API_ENDPOINT);
            myReq.Headers.Add("Authorization", "Bearer " + token);
            WebResponse myReqResp = myReq.GetResponse();
            System.IO.StreamReader myReqRespStream = new System.IO.StreamReader(myReqResp.GetResponseStream());
            Console.WriteLine(myReqRespStream.ReadToEnd());
            Console.WriteLine("");
            Console.WriteLine("Request Complete.");
            Console.ReadKey();
            Console.WriteLine("");

            #endregion

            // get a reference to the access token
            var httpClient = new OAuthHttpClient(token)
            {
                BaseAddress = new Uri(API_ENDPOINT)
            };

            Console.WriteLine("Calling web api...");
            Console.WriteLine("...");

            // make the request
            var response = httpClient.GetAsync("").Result;
            Console.WriteLine("Got Response");

            // if ok write the result
            if (response.StatusCode == HttpStatusCode.OK)
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            else
                Console.WriteLine("Error");

            Console.WriteLine();
            /*  */
            #endregion

            #region refreshing

            Console.WriteLine("Refreshing token ...");

            // first update the state to get a new token
            state = GetAccessToken(state.RefreshToken);

            tokenexpires = state.AccessTokenExpirationUtc;
            token = state.AccessToken;
            refresh = state.RefreshToken;

            Console.WriteLine("Refresh Expires = {0}", tokenexpires);
            Console.WriteLine();
            Console.WriteLine("Token = {0}", token);
            Console.WriteLine();

            httpClient = new OAuthHttpClient(token)
            {
                BaseAddress = new Uri(API_ENDPOINT)
            };

            Console.WriteLine("Enter to call web api...");
            Console.WriteLine("...");

            // make the request
            response = httpClient.GetAsync("").Result;
            Console.WriteLine("Got Response");

            // if ok write the result
            if (response.StatusCode == HttpStatusCode.OK)
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            else
                Console.WriteLine("Error");

            Console.WriteLine();
            Console.WriteLine("Finished calling API with refresh token");
            Console.WriteLine();
            /**/
            #endregion

            Console.WriteLine();
            Console.WriteLine("Done");
            Console.ReadLine();
        }