Rheya / devdefined-tools

Automatically exported from code.google.com/p/devdefined-tools
0 stars 0 forks source link

Problem in Signature for post params #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Submit a post with form fields where one form field is named UserId and 
another is named action.  Case is important. 

What is the expected output? What do you see instead?

When the signature is constructured, the UserId parameter and value must come 
before the action parameter.  This is not the case in the current 
implementation.

What version of the product are you using? On what operating system?

Please provide any additional information below.

Change UriUtility.cs with the below:

    /// <summary>
    /// Normalizes a sequence of key/value pair parameters as per the OAuth core specification.
    /// </summary>
    /// <param name="parameters"></param>
    /// <returns></returns>
    public static string NormalizeRequestParameters(IEnumerable<QueryParameter> parameters)
    {
      List<QueryParameter> orderedParameters = parameters
        .Select(
        x => new QueryParameter(x.Key, UrlEncode(x.Value))).ToList();
      orderedParameters.Sort(SignatureBaseStringParameterComparer);
      var builder = new StringBuilder();

      foreach (var parameter in orderedParameters)
      {
        if (builder.Length > 0) builder.Append("&");

        builder.Append(parameter.Key).Append("=").Append(parameter.Value);
      }

      return builder.ToString();
    }

    private static int SignatureBaseStringParameterComparer(QueryParameter left, QueryParameter right)
    {
        int result = string.CompareOrdinal(left.Key, right.Key);
        if (result != 0)
        {
            return result;
        }

        return string.CompareOrdinal(left.Value, right.Value);
    }

Original issue reported on code.google.com by alex.ga...@apptik.com on 17 Nov 2011 at 2:53