public override string GetSignature(OAuthRequestMethod method, string url, OAuthClient client, OAuthToken token, Dictionary <string, string> parameters) { var sortedParams = parameters.Select(p => p.Key).OrderBy(p => p).Select(k => $"{k}={Uri.EscapeDataString(parameters[k])}"); var parameterStrings = string.Join("&", sortedParams); var escapedMethod = Uri.EscapeDataString(method.ToString()); var escapedUrl = Uri.EscapeDataString(url); var escapedNormalizedParameters = Uri.EscapeDataString(parameterStrings); var rawData = $"{escapedMethod}&{escapedUrl}&{escapedNormalizedParameters}"; var key = $"{client.ConsumerSecret}&"; if (token != null) { key += token.Secret; } return(Convert.ToBase64String(new HMACSHA1(Encoding.UTF8.GetBytes(key)).ComputeHash(Encoding.UTF8.GetBytes(rawData)))); }
private static async Task Run(string url, OAuthRequestMethod method, Dictionary <string, string> parameters, Action <OAuthRequestResult> onSuccess, Action <OAuthRequestResult> onError, SynchronizationContext context) { var result = new OAuthRequestResult(); switch (method) { case OAuthRequestMethod.GET: { var response = await httpClient.GetAsync(url); var text = await response.Content.ReadAsStringAsync(); result.Text = text; result.IsSuccess = response.IsSuccessStatusCode; result.StatusCode = (long)response.StatusCode; } break; case OAuthRequestMethod.POST: { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url); var content = string.Join("&", parameters.Select(kvp => $"{kvp.Key}={Uri.EscapeDataString(kvp.Value)}")); request.Content = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded"); var response = await httpClient.SendAsync(request); var text = await response.Content.ReadAsStringAsync(); result.Text = text; result.IsSuccess = response.IsSuccessStatusCode; result.StatusCode = (long)response.StatusCode; } break; } context.Post(_ => { if (!result.IsSuccess) { onError(result); return; } onSuccess(result); }, null); }
public OAuthRequestHttpClient(string url, OAuthRequestMethod method) : base(url, method) { }
public OAuthRequestUnity(string url, OAuthRequestMethod method) : base(url, method) { }
public OAuthRequestObject(string url, OAuthRequestMethod method) { Url = url; Method = method; }
public abstract string GetSignature(OAuthRequestMethod method, string url, OAuthClient client, OAuthToken token, Dictionary <string, string> parameters);