Пример #1
0
        public string GenerateOAuthParametersForHeader()
        {
            var builder = new StringBuilder();

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

            foreach (
                var parameter in AuthorizationHeaderParameters.ToQueryParameters().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());
        }
Пример #2
0
        public string GenerateSignatureBase()
        {
            if (Token == null)
            {
                Token = string.Empty;
            }

            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 && RequestMethod == "POST")
            {
                allParameters.AddRange(FormEncodedParameters.ToQueryParameters());
            }
            if (QueryParameters != null)
            {
                allParameters.AddRange(QueryParameters.ToQueryParameters());
            }
            if (Cookies != null)
            {
                allParameters.AddRange(Cookies.ToQueryParameters());
            }
            if (AuthorizationHeaderParameters != null)
            {
                allParameters.AddRange(AuthorizationHeaderParameters.ToQueryParameters().Where(q => q.Key != Parameters.Realm));
            }

            // remove the signature parameter and the token parameter if it's not specified
            if (string.IsNullOrEmpty(Token))
            {
                allParameters.RemoveAll(param => param.Key == Parameters.OAuth_Token);
            }

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

            //allParameters.RemoveAll(param => param.Key == Parameters.OAuth_Token && string.IsNullOrEmpty(param.Value));

            // build the uri

            return(UriUtility.FormatParameters(RequestMethod, new Uri(NormalizedRequestUrl), allParameters));
        }
        public string GenerateSignatureBase()
        {
            if (Token == null)
            {
                Token = string.Empty;
            }

            if (string.IsNullOrEmpty(ConsumerKey))
            {
                throw Error.MissingRequiredOAuthParameter("ConsumerKey");
            }

            if (string.IsNullOrEmpty(SignatureMethod))
            {
                throw Error.MissingRequiredOAuthParameter("SignatureMethod");
            }

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

            var allParameters = new List <QueryParameter>();

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

            // remove the signature parameter

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

            // build the uri

            return(UriUtility.FormatParameters(RequestMethod, new Uri(NormalizedRequestUrl), allParameters));
        }
        public string GenerateOAuthParametersForHeader()
        {
            var builder = new StringBuilder();

            foreach (QueryParameter parameter in AuthorizationHeaderParameters.ToQueryParameters())
            {
                if (builder.Length > 0)
                {
                    builder.Append(",");
                }
                builder.Append(UriUtility.UrlEncode(parameter.Name)).Append("=\"").Append(
                    UriUtility.UrlEncode(parameter.Value)).Append("\"");
            }

            builder.Insert(0, "OAuth ");

            return(builder.ToString());
        }