Exemple #1
0
        public void Sign(Uri requestUri, string httpMethod, IConsumer consumer, IToken token, ISigningProvider signingProvider)
        {
            if (token != null)
            {
                this.Token = token.Token;
            }

            OAuthParameters signingParameters = this.Clone();
            var             signingUri        = new UriBuilder(requestUri);

            // Normalize the request uri for signing
            if (!string.IsNullOrEmpty(requestUri.Query))
            {
                // TODO: Will the parameters necessarily be Rfc3698 encoded here? If not, then Rfc3968.SplitAndDecode will throw FormatException
                signingParameters.AdditionalParameters.Add(Rfc3986.SplitAndDecode(requestUri.Query.Substring(1)));
                signingUri.Query = null;
            }

            if (signingProvider == null)
            {
                // There is no signing provider for this signature method
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            // Compute the signature
            this.Signature = signingProvider.ComputeSignature(
                SignatureBase.Create(httpMethod, signingUri.Uri, signingParameters),
                consumer.Secret,
                (token != null && token.Secret != null) ? token.Secret : null);
        }
Exemple #2
0
        private HttpWebRequest GenerateRequest(string contentType, string requestMethod)
        {
            var ts = UnixTime.ToUnixTime(DateTime.Now);
            //Create the needed OAuth Parameters.
            //Refer - http://oauth.net/core/1.0/#sig_base_example
            var param = new OAuthParameters()
            {
                ConsumerKey     = _consumerKey,
                SignatureMethod = SigningProvider.SignatureMethod,
                Version         = Constants.Version1_0,
                Nonce           = NonceProvider.GenerateNonce(ts),
                Timestamp       = ts.ToString(),
            };

            //Generate Signature Hash
            var signatureBase = SignatureBase.Create(requestMethod.ToUpper(), _serviceProviderUri, param);

            //Set Signature Hash as one of the OAuth Parameter
            param.Signature = SigningProvider.ComputeSignature(signatureBase, _consumerSecret, null);

            var httpWebRequest = (HttpWebRequest)WebRequest.Create(_serviceProviderUri);

            httpWebRequest.Method      = requestMethod;
            httpWebRequest.ContentType = contentType;
            httpWebRequest.Timeout     = RequestTimeOut;
            //Add the OAuth Parameters to Authorization Header of Request
            httpWebRequest.Headers.Add(Constants.AuthorizationHeaderParameter, param.ToHeaderFormat());
            return(httpWebRequest);
        }
        public void Sign(Uri requestUri, string httpMethod, IConsumer consumer, IToken token, ISigningProvider signingProvider)
        {
            if (token != null)
                this.Token = token.Token;

            OAuthParameters signingParameters = this.Clone();
            var signingUri = new UriBuilder(requestUri);

            // Normalize the request uri for signing
            if (!string.IsNullOrEmpty(requestUri.Query))
            {
                // TODO: Will the parameters necessarily be Rfc3698 encoded here? If not, then Rfc3968.SplitAndDecode will throw FormatException
                signingParameters.AdditionalParameters.Add(Rfc3986.SplitAndDecode(requestUri.Query.Substring(1)));
                signingUri.Query = null;
            }

            if (signingProvider == null)
            {
                // There is no signing provider for this signature method
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            // Compute the signature
            this.Signature = signingProvider.ComputeSignature(
                SignatureBase.Create(httpMethod, signingUri.Uri, signingParameters),
                consumer.Secret,
                (token != null && token.Secret != null) ? token.Secret : null);
        }