private string NormalizeRequestParameters(List <DiscuzOAuthParameter> parameters) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < parameters.Count; i++) { DiscuzOAuthParameter discuzOAuthParameter = parameters[i]; stringBuilder.AppendFormat("{0}={1}", discuzOAuthParameter.Name, Utils.PHPUrlEncode(discuzOAuthParameter.Value)); if (i < parameters.Count - 1) { stringBuilder.Append("&"); } } return(stringBuilder.ToString()); }
/// <summary> /// This is a different Url Encode implementation since the default .NET one outputs the percent encoding in lower case. /// While this is not a problem with the percent encoding spec, it is used in upper case throughout OAuth /// </summary> /// <param name="value">The value to Url encode</param> /// <returns>Returns a Url encoded string</returns> //private string UrlEncode(string value) //{ // StringBuilder result = new StringBuilder(); // byte[] byStr = System.Text.Encoding.UTF8.GetBytes(value); // foreach (byte symbol in byStr) // { // if (unreservedChars.IndexOf((char)symbol) != -1) // { // result.Append((char)symbol); // } // else // { // result.Append('%' + Convert.ToString((char)symbol, 16).ToUpper()); // } // } // return result.ToString(); //} /// <summary> /// Normalizes the request parameters according to the spec /// </summary> /// <param name="parameters">The list of parameters already sorted</param> /// <returns>a string representing the normalized parameters</returns> private string NormalizeRequestParameters(List <DiscuzOAuthParameter> parameters) { StringBuilder sb = new StringBuilder(); DiscuzOAuthParameter p = null; for (int i = 0; i < parameters.Count; i++) { p = parameters[i]; sb.AppendFormat("{0}={1}", p.Name, Utils.PHPUrlEncode(p.Value)); if (i < parameters.Count - 1) { sb.Append("&"); } } return(sb.ToString()); }