public void GetQueryParameters_ShouldReturnEmptyDictionaryForNoParameters()
        {
            var uri = new Uri("http://www.foo.bar/index.htm");
            var result = uri.GetQueryParameters();

            Assert.That(result.Count(), Is.EqualTo(0));
        }
        public void GetQueryParameters_ShouldReturnOneElementDictionaryForSingleParameter()
        {
            var uri = new Uri("http://www.foo.bar/index.htm?foo=bar");
            var result = uri.GetQueryParameters();

            Assert.That(result.Count(), Is.EqualTo(1));
            Assert.That(result.First().Key, Is.EqualTo("foo"));
            Assert.That(result.First().Value, Is.EqualTo("bar"));
        }
        public void GetQueryParameters_ShouldHandleBrokenParameter()
        {
            var uri = new Uri("http://www.foo.bar/index.htm?foo=bar&bar=foo&broken");
            var result = uri.GetQueryParameters();

            Assert.That(result.Count(), Is.EqualTo(3));
            Assert.That(result.First().Key, Is.EqualTo("foo"));
            Assert.That(result.First().Value, Is.EqualTo("bar"));
            Assert.That(result.ElementAt(1).Key, Is.EqualTo("bar"));
            Assert.That(result.ElementAt(1).Value, Is.EqualTo("foo"));
            Assert.That(result.Last().Key, Is.EqualTo("broken"));
            Assert.That(result.Last().Value, Is.EqualTo(""));
        }
示例#4
0
        public void Authorize(Uri verificationUri)
        {
            if (verificationUri == null) throw new ArgumentNullException("verificationUri");

            var verifier = verificationUri.GetQueryParameters()["oauth_verifier"];
            var entity = GetAdapterSettings();

            if (string.IsNullOrEmpty(verifier) || entity.OAuthRequestToken == null)
            {
                throw new AuthorizationException();
            }

            var accessToken = PhotoAdapter.GetOAuthAccessToken(entity.OAuthRequestToken, verifier);
            entity.OAuthRequestToken = null;
            entity.OAuthAccessToken = accessToken;
            UpdateAdapterSettings(entity);
        }
示例#5
0
        /// <summary>
        /// Requests an <see cref="OAuth2Token"/> using the <see cref="Uri"/> that was requested after the Authorization by the user.
        /// </summary>
        /// <param name="responseUri">The complete <see cref="Uri"/> of the request after Authorization.</param>
        /// <param name="clientSecret">The api secret of the app.</param>
        /// <returns>An <see cref="OAuth2Token"/> that can be used to access protected resources.</returns>
        public OAuth2Token RequestOAuthToken(Uri responseUri, string clientSecret)
        {
            if (responseUri == null) throw new ArgumentNullException("responseUri");

            if (_soundCloudClient.RedirectUri == null)
            {
                var baseUrl = new Uri(responseUri.GetLeftPart(UriPartial.Authority));
                _soundCloudClient.RedirectUri = new Uri(baseUrl, responseUri.AbsolutePath);
            }

            var queryPairs = responseUri.GetQueryParameters();
            if (queryPairs.ContainsKey("error"))
            {
                throw new ArgumentException(string.Format("Error: {0}, Description: {1}", queryPairs["error"], queryPairs["error_description"]));
            }

            return _soundCloudClient.OAuthToken = _soundCloudClient.RequestOAuthToken(queryPairs["code"], clientSecret);
        }