public static Uri BuildRequestUri(this AccessToken accessToken, VerificationCode verificationCode, BaseSpaceClientSettings settings)
        {
            NameValueCollection queryPairs =
                new NameValueCollection
                {
                    {"client_id", settings.AppClientId},
                    {"client_secret", settings.AppClientSecret},
                    {"code", verificationCode.DeviceCode},
                    {"grant_type", "device"}
                };

            return new Uri(string.Format("{0}/{1}/oauthv2/token?{2}", settings.BaseSpaceApiUrl, settings.Version, RequestUrlExtensions.ToQueryString(queryPairs)));
        }
        private static VerificationCode FetchVerificationCode(BaseSpaceClientSettings settings)
        {
            VerificationCode verificationCode = new VerificationCode();
            var verificationUri = verificationCode.BuildRequestUri(settings);
            if ((verificationUri == null) || string.IsNullOrEmpty(verificationUri.AbsoluteUri))
                return null; // TODO: throw exception

            string jsonResponse = HttpPost(verificationUri, string.Empty);
            verificationCode.FromJson(jsonResponse);

            return verificationCode;
        }
        private static AccessToken FetchAccessToken(VerificationCode verificationCode, BaseSpaceClientSettings settings)
        {
            AccessToken accessToken = null;
            Int32 interval = verificationCode.Interval * 1000;

            // TODO: use the new "await" instead of looping
            // TODO: we should have a hard stop at some useful limit of time
            while (accessToken == null)
            {
                Thread.Sleep(interval);

                try
                {
                    // TODO: wrap in try-catch with System.Net.WebException handler
                    Uri authUri = accessToken.BuildRequestUri(verificationCode, settings);
                    string jsonResponse = HttpPost(authUri, string.Empty);
                    //string response = HttpPost(authVerificationCode.VerificationWithCodeUri.AbsoluteUri, string.Empty);
                    // TODO: convert to using 200 response
                    if ((!string.IsNullOrEmpty(jsonResponse) && !jsonResponse.Contains("DOCTYPE")))
                    {
                        accessToken = new AccessToken();
                        accessToken.FromJson(jsonResponse);
                        //// TODO: add sensitivity to return value, e.g., 404
                        //switch(response.getClientResponseStatus())
                        //{
                        //    case BAD_REQUEST:
                        //        AccessToken token = mapper.readValue(response.getEntity(string.class), AccessToken.class);
                        //        if (token.getError().equalsIgnoreCase(ACCESS_DENIED))
                        //        {
                        //            throw new AccessDeniedException();
                        //        }
                        //        break;
                        //    case OK:
                        //        token = mapper.readValue(response.getEntity(string.class), AccessToken.class);
                        //        accessToken = token.getAccessToken();
                        //}
                    }

                }
                catch (System.Net.WebException)
                {
                    // ignore these exceptions
                    continue;
                    //throw;
                }
            }
            return accessToken;
        }