Exemplo n.º 1
0
        /// <summary>
        /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an
        /// <see cref="IAuthenticator" /> 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 virtual OAuthWebQueryInfo BuildRequestTokenInfo(string 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, SignatureTreatment, signatureBase, ConsumerSecret);
            var info          = new OAuthWebQueryInfo
            {
                WebMethod          = method,
                ParameterHandling  = ParameterHandling,
                ConsumerKey        = ConsumerKey,
                SignatureMethod    = SignatureMethod.ToRequestValue(),
                SignatureTreatment = SignatureTreatment,
                Signature          = signature,
                Timestamp          = timestamp,
                Nonce          = nonce,
                Version        = Version ?? "1.0",
                Callback       = OAuthTools.UrlEncodeRelaxed(CallbackUrl ?? ""),
                TokenSecret    = TokenSecret,
                ConsumerSecret = ConsumerSecret
            };

            return(info);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an
        /// <see cref="IAuthenticator" /> 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 virtual OAuthWebQueryInfo BuildClientAuthAccessTokenInfo(string method, WebParameterCollection parameters)
        {
            ValidateClientAuthAccessRequestState();
            if (parameters == null)
            {
                parameters = new WebParameterCollection();
            }
            var uri       = new Uri(AccessTokenUrl);
            var timestamp = OAuthTools.GetTimestamp();
            var nonce     = OAuthTools.GetNonce();

            AddXAuthParameters(parameters, timestamp, nonce);
            var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), parameters);
            var signature     = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret);
            var info          = new OAuthWebQueryInfo
            {
                WebMethod          = method,
                ParameterHandling  = ParameterHandling,
                ClientMode         = "client_auth",
                ClientUsername     = ClientUsername,
                ClientPassword     = ClientPassword,
                ConsumerKey        = ConsumerKey,
                SignatureMethod    = SignatureMethod.ToRequestValue(),
                SignatureTreatment = SignatureTreatment,
                Signature          = signature,
                Timestamp          = timestamp,
                Nonce          = nonce,
                Version        = Version ?? "1.0",
                TokenSecret    = TokenSecret,
                ConsumerSecret = ConsumerSecret
            };

            return(info);
        }
Exemplo n.º 3
0
        public virtual OAuthWebQueryInfo BuildClientAuthAccessTokenInfo(string method, WebParameterCollection parameters)
        {
            ValidateClientAuthAccessRequestState();
            if (parameters == null)
            {
                parameters = new WebParameterCollection();
            }
            Uri    uri       = new Uri(AccessTokenUrl);
            string timestamp = OAuthTools.GetTimestamp();
            string nonce     = OAuthTools.GetNonce();

            AddXAuthParameters(parameters, timestamp, nonce);
            string            signatureBase     = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), parameters);
            string            signature         = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret);
            OAuthWebQueryInfo oAuthWebQueryInfo = new OAuthWebQueryInfo();

            oAuthWebQueryInfo.WebMethod          = method;
            oAuthWebQueryInfo.ParameterHandling  = ParameterHandling;
            oAuthWebQueryInfo.ClientMode         = "client_auth";
            oAuthWebQueryInfo.ClientUsername     = ClientUsername;
            oAuthWebQueryInfo.ClientPassword     = ClientPassword;
            oAuthWebQueryInfo.ConsumerKey        = ConsumerKey;
            oAuthWebQueryInfo.SignatureMethod    = SignatureMethod.ToRequestValue();
            oAuthWebQueryInfo.SignatureTreatment = SignatureTreatment;
            oAuthWebQueryInfo.Signature          = signature;
            oAuthWebQueryInfo.Timestamp          = timestamp;
            oAuthWebQueryInfo.Nonce          = nonce;
            oAuthWebQueryInfo.Version        = (Version ?? "1.0");
            oAuthWebQueryInfo.TokenSecret    = TokenSecret;
            oAuthWebQueryInfo.ConsumerSecret = ConsumerSecret;
            return(oAuthWebQueryInfo);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an
        /// <see cref="IAuthenticator" /> for the purpose of exchanging a request token
        /// 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://oauth.net/core/1.0#anchor9"/>
        /// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
        public virtual OAuthWebQueryInfo BuildAccessTokenInfo(string method, WebParameterCollection parameters)
        {
            ValidateAccessRequestState();
            if (parameters == null)
            {
                parameters = new WebParameterCollection();
            }
            var uri       = new Uri(AccessTokenUrl);
            var timestamp = OAuthTools.GetTimestamp();
            var nonce     = OAuthTools.GetNonce();

            AddAuthParameters(parameters, timestamp, nonce);
            var signatureBase = OAuthTools.ConcatenateRequestElements(method, uri.ToString(), parameters);
            var signature     = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret);
            var info          = new OAuthWebQueryInfo
            {
                WebMethod          = method,
                ParameterHandling  = ParameterHandling,
                ConsumerKey        = ConsumerKey,
                Token              = Token,
                SignatureMethod    = SignatureMethod.ToRequestValue(),
                SignatureTreatment = SignatureTreatment,
                Signature          = signature,
                Timestamp          = timestamp,
                Nonce              = nonce,
                Version            = Version ?? "1.0",
                Verifier           = Verifier,
                Callback           = CallbackUrl,
                TokenSecret        = TokenSecret,
                ConsumerSecret     = ConsumerSecret,
            };

            return(info);
        }
Exemplo n.º 5
0
        public virtual OAuthWebQueryInfo BuildRequestTokenInfo(string method, WebParameterCollection parameters)
        {
            ValidateTokenRequestState();
            if (parameters == null)
            {
                parameters = new WebParameterCollection();
            }
            string timestamp = OAuthTools.GetTimestamp();
            string nonce     = OAuthTools.GetNonce();

            AddAuthParameters(parameters, timestamp, nonce);
            string            signatureBase     = OAuthTools.ConcatenateRequestElements(method, RequestTokenUrl, parameters);
            string            signature         = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret);
            OAuthWebQueryInfo oAuthWebQueryInfo = new OAuthWebQueryInfo();

            oAuthWebQueryInfo.WebMethod          = method;
            oAuthWebQueryInfo.ParameterHandling  = ParameterHandling;
            oAuthWebQueryInfo.ConsumerKey        = ConsumerKey;
            oAuthWebQueryInfo.SignatureMethod    = SignatureMethod.ToRequestValue();
            oAuthWebQueryInfo.SignatureTreatment = SignatureTreatment;
            oAuthWebQueryInfo.Signature          = signature;
            oAuthWebQueryInfo.Timestamp          = timestamp;
            oAuthWebQueryInfo.Nonce          = nonce;
            oAuthWebQueryInfo.Version        = (Version ?? "1.0");
            oAuthWebQueryInfo.Callback       = OAuthTools.UrlEncodeRelaxed(CallbackUrl ?? "");
            oAuthWebQueryInfo.TokenSecret    = TokenSecret;
            oAuthWebQueryInfo.ConsumerSecret = ConsumerSecret;
            return(oAuthWebQueryInfo);
        }
Exemplo n.º 6
0
        public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string 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 && !WINDOWS_PHONE
            var urlParameters = HttpUtility.ParseQueryString(uri.Query);
#else
            var urlParameters = uri.Query.ParseQueryString();
#endif
#if !SILVERLIGHT && !WINDOWS_PHONE
            foreach (var parameter in urlParameters.AllKeys)
#else
            foreach (var parameter in urlParameters.Keys)
#endif
            {
                switch (method.ToUpperInvariant())
                {
                case "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, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret
                );
            var info = new OAuthWebQueryInfo
            {
                WebMethod          = method,
                ParameterHandling  = ParameterHandling,
                ConsumerKey        = ConsumerKey,
                Token              = Token,
                SignatureMethod    = SignatureMethod.ToRequestValue(),
                SignatureTreatment = SignatureTreatment,
                Signature          = signature,
                Timestamp          = timestamp,
                Nonce              = nonce,
                Version            = Version ?? "1.0",
                Callback           = CallbackUrl,
                ConsumerSecret     = ConsumerSecret,
                TokenSecret        = TokenSecret
            };
            return(info);
        }
Exemplo n.º 7
0
        public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string method, WebParameterCollection parameters,
                                                                    string url)
        {
            ValidateProtectedResourceState();

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

            // Include url parameters in query pool...
            var uri           = new Uri(url);
            var urlParameters = System.Web.HttpUtility.ParseQueryString(uri.Query);

            //...unless they were already present at some point, such as being added to the request object
            foreach (var parameter in urlParameters.AllKeys.Where(k => !parameters.Names.Contains(k)))
            {
                switch (method.ToUpperInvariant())
                {
                case "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, SignatureTreatment, signatureBase,
                                                        ConsumerSecret, TokenSecret);

            var info = new OAuthWebQueryInfo
            {
                WebMethod          = method,
                ParameterHandling  = ParameterHandling,
                ConsumerKey        = ConsumerKey,
                Token              = Token,
                SignatureMethod    = SignatureMethod.ToRequestValue(),
                SignatureTreatment = SignatureTreatment,
                Signature          = signature,
                Timestamp          = timestamp,
                Nonce              = nonce,
                Version            = Version ?? "1.0",
                Callback           = CallbackUrl,
                ConsumerSecret     = ConsumerSecret,
                TokenSecret        = TokenSecret
            };

            return(info);
        }
Exemplo n.º 8
0
        public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string method, WebParameterCollection parameters, string url)
        {
            ValidateProtectedResourceState();
            if (parameters == null)
            {
                parameters = new WebParameterCollection();
            }
            Uri uri = new Uri(url);
            NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(uri.Query);

            string[] allKeys = nameValueCollection.AllKeys;
            foreach (string name in allKeys)
            {
                string text = method.ToUpperInvariant();
                if (text != null && text == "POST")
                {
                    parameters.Add(new HttpPostParameter(name, nameValueCollection[name]));
                }
                else
                {
                    parameters.Add(name, nameValueCollection[name]);
                }
            }
            string timestamp = OAuthTools.GetTimestamp();
            string nonce     = OAuthTools.GetNonce();

            AddAuthParameters(parameters, timestamp, nonce);
            string            signatureBase     = OAuthTools.ConcatenateRequestElements(method, url, parameters);
            string            signature         = OAuthTools.GetSignature(SignatureMethod, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret);
            OAuthWebQueryInfo oAuthWebQueryInfo = new OAuthWebQueryInfo();

            oAuthWebQueryInfo.WebMethod          = method;
            oAuthWebQueryInfo.ParameterHandling  = ParameterHandling;
            oAuthWebQueryInfo.ConsumerKey        = ConsumerKey;
            oAuthWebQueryInfo.Token              = Token;
            oAuthWebQueryInfo.SignatureMethod    = SignatureMethod.ToRequestValue();
            oAuthWebQueryInfo.SignatureTreatment = SignatureTreatment;
            oAuthWebQueryInfo.Signature          = signature;
            oAuthWebQueryInfo.Timestamp          = timestamp;
            oAuthWebQueryInfo.Nonce              = nonce;
            oAuthWebQueryInfo.Version            = (Version ?? "1.0");
            oAuthWebQueryInfo.Callback           = CallbackUrl;
            oAuthWebQueryInfo.ConsumerSecret     = ConsumerSecret;
            oAuthWebQueryInfo.TokenSecret        = TokenSecret;
            return(oAuthWebQueryInfo);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an
        /// <see cref="IAuthenticator" /> 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 virtual OAuthWebQueryInfo BuildRequestTokenInfo(string 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, SignatureTreatment, signatureBase, ConsumerSecret);

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

            return info;
        }
Exemplo n.º 10
0
        public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string 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 && !WINDOWS_PHONE && !PocketPC && !WINDOWS_UAP
            var urlParameters = HttpUtility.ParseQueryString(uri.Query);
#else
            var urlParameters = uri.Query.ParseQueryString();
#endif

#if !SILVERLIGHT && !WINDOWS_PHONE && !PocketPC && !WINDOWS_UAP
            foreach (var parameter in urlParameters.AllKeys)
#else
            foreach (var parameter in urlParameters.Keys)
#endif
            {
#if PocketPC
                switch (method.ToUpper())
#else
                switch (method.ToUpperInvariant())
#endif
                {
                    case "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, SignatureTreatment, signatureBase, ConsumerSecret, TokenSecret);

            var info = new OAuthWebQueryInfo
            {
                WebMethod = method,
                ParameterHandling = ParameterHandling,
                ConsumerKey = ConsumerKey,
                Token = Token,
                SignatureMethod = SignatureMethod.ToRequestValue(),
                SignatureTreatment = SignatureTreatment,
                Signature = signature,
                Timestamp = timestamp,
                Nonce = nonce,
                Version = Version ?? "1.0",
                Callback = CallbackUrl,
                ConsumerSecret = ConsumerSecret,
                TokenSecret = TokenSecret
            };

            return info;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an
        /// <see cref="IAuthenticator" /> 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 virtual OAuthWebQueryInfo BuildClientAuthAccessTokenInfo(string method, WebParameterCollection parameters)
        {
            ValidateClientAuthAccessRequestState();

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

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

            AddXAuthParameters(parameters, timestamp, nonce);

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

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

            return info;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Generates a <see cref="OAuthWebQueryInfo"/> instance to pass to an
        /// <see cref="IAuthenticator" /> for the purpose of exchanging a request token
        /// 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://oauth.net/core/1.0#anchor9"/>
        /// <param name="parameters">Any existing, non-OAuth query parameters desired in the request</param>
        public virtual OAuthWebQueryInfo BuildAccessTokenInfo(string method, WebParameterCollection parameters)
        {
            ValidateAccessRequestState();

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

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

            AddAuthParameters(parameters, timestamp, nonce);

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

            var info = new OAuthWebQueryInfo
            {
                WebMethod = method,
                ParameterHandling = ParameterHandling,
                ConsumerKey = ConsumerKey,
                Token = Token,
                SignatureMethod = SignatureMethod.ToRequestValue(),
                SignatureTreatment = SignatureTreatment,
                Signature = signature,
                Timestamp = timestamp,
                Nonce = nonce,
                Version = Version ?? "1.0",
                Verifier = Verifier,
                Callback = CallbackUrl,
                TokenSecret = TokenSecret,
                ConsumerSecret = ConsumerSecret,
            };

            return info;
        }
Exemplo n.º 13
0
        public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string method, WebParameterCollection parameters,
                                                                    string url)
        {
            this.ValidateProtectedResourceState();

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

            Trace.WriteLine(string.Format("BuildProtectedResourceInfo: URL {0}", url));
            foreach (var param in parameters)
            {
                Trace.WriteLine(string.Format("BuildProtectedResourceInfo: PARAM {0} = {1}", param.Name, param.Value));
            }

            // Include url parameters in query pool
            Uri uri = new Uri(url);

#if !SILVERLIGHT && !WINDOWS_PHONE
            NameValueCollection urlParameters = HttpUtility.ParseQueryString(uri.Query);
#else
            IDictionary <string, string> urlParameters = uri.Query.ParseQueryString();
#endif

#if !SILVERLIGHT && !WINDOWS_PHONE
            foreach (string parameter in urlParameters.AllKeys)
#else
            foreach (string parameter in urlParameters.Keys)
#endif
            {
                switch (method.ToUpperInvariant())
                {
                case "POST":
                    parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter]));
                    break;

                default:
                    parameters.Add(parameter, urlParameters[parameter]);
                    break;
                }
            }

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

            this.AddAuthParameters(parameters, timestamp, nonce);

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

            OAuthWebQueryInfo info = new OAuthWebQueryInfo
            {
                WebMethod          = method,
                ParameterHandling  = this.ParameterHandling,
                ConsumerKey        = this.ConsumerKey,
                Token              = this.Token,
                SignatureMethod    = this.SignatureMethod.ToRequestValue(),
                SignatureTreatment = this.SignatureTreatment,
                Signature          = signature,
                Timestamp          = timestamp,
                Nonce              = nonce,
                Version            = this.Version ?? "1.0",
                Callback           = this.CallbackUrl,
                ConsumerSecret     = this.ConsumerSecret,
                TokenSecret        = this.TokenSecret
            };

            return(info);
        }
Exemplo n.º 14
0
        public virtual OAuthWebQueryInfo BuildProtectedResourceInfo(string method, WebParameterCollection parameters,
            string url)
        {
            this.ValidateProtectedResourceState();

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

            // Include url parameters in query pool
            Uri uri = new Uri(url);
#if !SILVERLIGHT && !WINDOWS_PHONE
            NameValueCollection urlParameters = HttpUtility.ParseQueryString(uri.Query);
#else
            IDictionary<string, string> urlParameters = uri.Query.ParseQueryString();
#endif

#if !SILVERLIGHT && !WINDOWS_PHONE
            foreach (string parameter in urlParameters.AllKeys)
#else
            foreach (string parameter in urlParameters.Keys)
#endif
            {
                switch (method.ToUpperInvariant())
                {
                    case "POST":
                        parameters.Add(new HttpPostParameter(parameter, urlParameters[parameter]));
                        break;

                    default:
                        parameters.Add(parameter, urlParameters[parameter]);
                        break;
                }
            }

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

            this.AddAuthParameters(parameters, timestamp, nonce);

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

            OAuthWebQueryInfo info = new OAuthWebQueryInfo
                                     {
                                         WebMethod = method,
                                         ParameterHandling = this.ParameterHandling,
                                         ConsumerKey = this.ConsumerKey,
                                         Token = this.Token,
                                         SignatureMethod = this.SignatureMethod.ToRequestValue(),
                                         SignatureTreatment = this.SignatureTreatment,
                                         Signature = signature,
                                         Timestamp = timestamp,
                                         Nonce = nonce,
                                         Version = this.Version ?? "1.0",
                                         Callback = this.CallbackUrl,
                                         ConsumerSecret = this.ConsumerSecret,
                                         TokenSecret = this.TokenSecret
                                     };

            return info;
        }