Exemplo n.º 1
0
        /// <summary>
        /// Generate OAuth parameters for header.
        /// </summary>
        /// <returns>The generated value.</returns>
        public string GenerateOAuthParametersForHeader()
        {
            var builder = new StringBuilder();

            if (Realm != null)
            {
                builder.Append("realm=\"").Append(Realm).Append("\"");
            }

            IEnumerable <QueryParameter> parameters = AuthorizationHeaderParameters.ToQueryParametersExcludingTokenSecret();

            foreach (
                var parameter in parameters.Where(p => p.Key != Parameters.Realm)
                )
            {
                if (builder.Length > 0)
                {
                    builder.Append(",");
                }
                builder.Append(UriUtility.UrlEncode(parameter.Key)).Append("=\"").Append(
                    UriUtility.UrlEncode(parameter.Value)).Append("\"");
            }

            builder.Insert(0, "OAuth ");

            return(builder.ToString());
        }
Exemplo n.º 2
0
        public IEnumerable <string> GenerateSignatureBase()
        {
            if (string.IsNullOrEmpty(ConsumerKey))
            {
                throw Error.MissingRequiredOAuthParameter(this, Parameters.OAuth_Consumer_Key);
            }

            if (string.IsNullOrEmpty(SignatureMethod))
            {
                throw Error.MissingRequiredOAuthParameter(this, Parameters.OAuth_Signature_Method);
            }

            if (string.IsNullOrEmpty(RequestMethod))
            {
                throw Error.RequestMethodHasNotBeenAssigned("RequestMethod");
            }

            if (IncludeOAuthRequestBodyHashInSignature)
            {
                GenerateAndSetBodyHash();
            }

            var allParameters = new List <QueryParameter>();

            //fix for issue: http://groups.google.com/group/oauth/browse_thread/thread/42ef5fecc54a7e9a/a54e92b13888056c?hl=en&lnk=gst&q=Signing+PUT+Request#a54e92b13888056c
            if (FormEncodedParameters != null && RequestMethod == "POST")
            {
                allParameters.AddRange(FormEncodedParameters.ToQueryParametersExcludingTokenSecret());
            }

            if (QueryParameters != null)
            {
                allParameters.AddRange(QueryParameters.ToQueryParametersExcludingTokenSecret());
            }

            if (Cookies != null)
            {
                allParameters.AddRange(Cookies.ToQueryParametersExcludingTokenSecret());
            }

            if (AuthorizationHeaderParameters != null)
            {
                allParameters.AddRange(
                    AuthorizationHeaderParameters.ToQueryParametersExcludingTokenSecret()
                    .Where(q => q.Key != Parameters.Realm));
            }

            // patch from http://code.google.com/p/devdefined-tools/issues/detail?id=10
            //if(RawContent != null)
            //    allParameters.Add(new QueryParameter("raw", RawContent));

            allParameters.RemoveAll(param => param.Key == Parameters.OAuth_Signature);

            foreach (
                var signatureBase in
                UriUtility.FormatParameters(RequestMethod, new Uri(NormalizedRequestUrl), allParameters))
            {
                yield return(signatureBase);
            }
        }
Exemplo n.º 3
0
        public string GenerateSignatureBase()
        {
            if (string.IsNullOrEmpty(ConsumerKey))
            {
                throw Error.MissingRequiredOAuthParameter(this, Parameters.OAuth_Consumer_Key);
            }

            if (string.IsNullOrEmpty(SignatureMethod))
            {
                throw Error.MissingRequiredOAuthParameter(this, Parameters.OAuth_Signature_Method);
            }

            if (string.IsNullOrEmpty(RequestMethod))
            {
                throw Error.RequestMethodHasNotBeenAssigned("RequestMethod");
            }

            var allParameters = new List <QueryParameter>();

            //fix for issue: http://groups.google.com/group/oauth/browse_thread/thread/42ef5fecc54a7e9a/a54e92b13888056c?hl=en&lnk=gst&q=Signing+PUT+Request#a54e92b13888056c
            if (FormEncodedParameters != null && RequestMethod == "POST")
            {
                allParameters.AddRange(FormEncodedParameters.ToQueryParametersExcludingTokenSecret());
            }

            if (QueryParameters != null)
            {
                allParameters.AddRange(QueryParameters.ToQueryParametersExcludingTokenSecret());
            }

            if (Cookies != null)
            {
                allParameters.AddRange(Cookies.ToQueryParametersExcludingTokenSecret());
            }

            if (AuthorizationHeaderParameters != null)
            {
                allParameters.AddRange(AuthorizationHeaderParameters.ToQueryParametersExcludingTokenSecret().Where(q => q.Key != Parameters.Realm));
            }

            allParameters.RemoveAll(param => param.Key == Parameters.OAuth_Signature);

            string signatureBase = UriUtility.FormatParameters(RequestMethod, new Uri(NormalizedRequestUrl), allParameters);

            return(signatureBase);
        }
Exemplo n.º 4
0
        public string GenerateSignatureBase()
        {
            if (string.IsNullOrEmpty(ConsumerKey))
            {
                throw Error.MissingRequiredOAuthParameter(this, Parameters.OAuth_Consumer_Key);
            }

            if (string.IsNullOrEmpty(SignatureMethod))
            {
                throw Error.MissingRequiredOAuthParameter(this, Parameters.OAuth_Signature_Method);
            }

            if (string.IsNullOrEmpty(RequestMethod))
            {
                throw Error.RequestMethodHasNotBeenAssigned("RequestMethod");
            }

            var allParameters = new List <QueryParameter>();

            if (FormEncodedParameters != null)
            {
                allParameters.AddRange(FormEncodedParameters.ToQueryParametersExcludingTokenSecret());
            }
            if (QueryParameters != null)
            {
                allParameters.AddRange(QueryParameters.ToQueryParametersExcludingTokenSecret());
            }
            if (Cookies != null)
            {
                allParameters.AddRange(Cookies.ToQueryParametersExcludingTokenSecret());
            }
            if (AuthorizationHeaderParameters != null)
            {
                allParameters.AddRange(AuthorizationHeaderParameters.ToQueryParametersExcludingTokenSecret().Where(q => q.Key != Parameters.Realm));
            }

            allParameters.RemoveAll(param => param.Key == Parameters.OAuth_Signature);

            string signatureBase = UriUtility.FormatParameters(RequestMethod, new Uri(NormalizedRequestUrl), allParameters);

            return(signatureBase);
        }