Beispiel #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)
        {
            this.ValidateTokenRequestState();

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

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

            this.AddAuthParameters(parameters, timestamp, nonce);

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

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

            return(info);
        }
Beispiel #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)
        {
            this.ValidateClientAuthAccessRequestState();

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

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

            this.AddXAuthParameters(parameters, timestamp, nonce);

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

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

            return(info);
        }
Beispiel #3
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);
        }