/// <summary>
        /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an
        /// <see cref="OAuthWebQuery" /> for the purpose of requesting an
        /// unauthorized request token.
        /// </summary>
        /// <param name="method">The HTTP method for the intended request</param>
        /// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
        /// <seealso cref="http://oauth.net/core/1.0#anchor9"/>
        /// <returns></returns>
        public OAuthWebQueryInfo BuildRequestTokenInfo(WebMethod method, WebParameterCollection parameters)
        {
            ValidateTokenRequestState();

            if (parameters == null)
            {
                parameters = new WebParameterCollection();
            }

            var timestamp = OAuthTools.GetTimestamp();
            var nonce = OAuthTools.GetNonce();

            AddAuthParameters(parameters, timestamp, nonce);

            var signatureBase = OAuthTools.ConcatenateRequestElements(method, RequestTokenUrl, parameters);
            var signature = OAuthTools.GetSignature(SignatureMethod, signatureBase, ConsumerSecret);

            var info = new OAuthWebQueryInfo
                           {
                               WebMethod = method,
                               ParameterHandling = ParameterHandling,
                               ConsumerKey = ConsumerKey,
                               SignatureMethod = SignatureMethod.ToRequestValue(),
                               Signature = signature,
                               Timestamp = timestamp,
                               Nonce = nonce,
                               Version = OAUTH_VERSION,
                               Callback = OAuthTools.UrlEncode(CallbackUrl ?? ""),
                               UserAgent = "TweetSharp",
                               TokenSecret = TokenSecret,
                               ConsumerSecret = ConsumerSecret
                           };

            return info;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OAuthWebQuery"/> class.
 /// </summary>
 /// <param name="info">The info.</param>
 public OAuthWebQuery(OAuthWebQueryInfo info)
     : base(info)
 {
     Method = info.WebMethod;
     ParameterHandling = info.ParameterHandling;
 }
        public OAuthWebQueryInfo BuildProtectedResourceInfo(WebMethod method, WebParameterCollection parameters,
                                                            string url)
        {
            ValidateProtectedResourceState();

            if (parameters == null)
            {
                parameters = new WebParameterCollection();
            }

            // Include url parameters in query pool
            var uri = new Uri(url);
#if !SILVERLIGHT
            var urlParameters = HttpUtility.ParseQueryString(uri.Query);
#else
            var urlParameters = uri.Query.ParseQueryString();
#endif

#if !SILVERLIGHT
            foreach (var parameter in urlParameters.AllKeys)
#else
            // todo can we just use keys instead of allkeys?
            foreach (var parameter in urlParameters.Keys)
#endif
            {
                switch (method)
                {
                    case WebMethod.Post:
                        parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter]));
                        break;
                    default:
                        parameters.Add(parameter, urlParameters[parameter]);
                        break;
                }
            }

            var timestamp = OAuthTools.GetTimestamp();
            var nonce = OAuthTools.GetNonce();

            AddAuthParameters(parameters, timestamp, nonce);

            var signatureBase = OAuthTools.ConcatenateRequestElements(method, url, parameters);
            var signature = OAuthTools.GetSignature(SignatureMethod, signatureBase, ConsumerSecret, TokenSecret);

            var info = new OAuthWebQueryInfo
                           {
                               WebMethod = method,
                               ParameterHandling = ParameterHandling,
                               ConsumerKey = ConsumerKey,
                               Token = Token,
                               SignatureMethod = SignatureMethod.ToRequestValue(),
                               Signature = signature,
                               Timestamp = timestamp,
                               Nonce = nonce,
                               Version = OAUTH_VERSION,
                               UserAgent = "TweetSharp",
                               ConsumerSecret = ConsumerSecret,
                               TokenSecret = TokenSecret
                           };

            return info;
        }
        /// <summary>
        /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an
        /// <see cref="OAuthWebQuery" /> for the purpose of exchanging user credentials
        /// for an access token authorized by the user at the Service Provider site.
        /// </summary>
        /// <param name="method">The HTTP method for the intended request</param>
        /// <seealso cref="http://tools.ietf.org/html/draft-dehora-farrell-oauth-accesstoken-creds-00#section-4"/>
        /// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
        public OAuthWebQueryInfo BuildClientAuthAccessTokenInfo(WebMethod method, WebParameterCollection parameters)
        {
            ValidateClientAuthAccessRequestState();

            if (parameters == null)
            {
                parameters = new WebParameterCollection();
            }

            var uri = new Uri(AccessTokenUrl);
            var timestamp = OAuthTools.GetTimestamp();
            var nonce = OAuthTools.GetNonce();

            AddClientAuthParameters(parameters, timestamp, nonce);

            var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), parameters);
            var signature = OAuthTools.GetSignature(SignatureMethod, signatureBase, ConsumerSecret);

            var info = new OAuthWebQueryInfo
                           {
                               WebMethod = method,
                               ParameterHandling = ParameterHandling,
                               ClientMode = "client_auth",
                               ClientUsername = ClientUsername,
                               ClientPassword = ClientPassword,
                               ConsumerKey = ConsumerKey,
                               SignatureMethod = SignatureMethod.ToRequestValue(),
                               Signature = signature,
                               Timestamp = timestamp,
                               Nonce = nonce,
                               Version = OAUTH_VERSION,
                               UserAgent = "TweetSharp",
                               TokenSecret = TokenSecret,
                               ConsumerSecret = ConsumerSecret
                           };

            return info;
        }