private async void button1_Click(object sender, EventArgs e) { requestToken = await MyService.GetRequestToken(); string url = MyService.GetAuthorizeRequestTokenUrl(requestToken); //External browser //System.Diagnostics.Process.Start(url); //Internal Browser webBrowser1.Navigate(url); }
public FiveHundredPxService(string consumerKey, string consumerSecret, string callbackUrl, OAuthToken token) { _callbackUrl = callbackUrl; _consumerKey = consumerKey; _consumerSecret = consumerSecret; AccessToken = token; }
private string GenerateSignature(Uri url, OAuthToken token, string httpMethod, out string normalizedUrl, out string normalizedRequestParameters) { if (token.Token == null) { token.Token = string.Empty; } if (token.Secret == null) { token.Secret = string.Empty; } if (string.IsNullOrEmpty(httpMethod)) { throw new ArgumentNullException("httpMethod"); } var parameters = GetQueryParameters(url.OriginalString); parameters.Add(new QueryParameter(OAuthParameter.Version, UrlEncode(OAuthVersion))); parameters.Add(new QueryParameter(OAuthParameter.Nonce, UrlEncode(GenerateNonce()))); parameters.Add(new QueryParameter(OAuthParameter.Timestamp, UrlEncode(GenerateTimeStamp()))); parameters.Add(new QueryParameter(OAuthParameter.SignatureMethod, UrlEncode(OAuthSignatureMethod))); parameters.Add(new QueryParameter(OAuthParameter.ConsumerKey, UrlEncode(_consumerKey))); parameters.Add(new QueryParameter(OAuthParameter.Callback, _callbackUrl)); if (!string.IsNullOrEmpty(token.Token)) { parameters.Add(new QueryParameter(OAuthParameter.Token, token.Token)); } if (!string.IsNullOrWhiteSpace(token.Verifier)) { parameters.Add(new QueryParameter(OAuthParameter.Verifier, token.Verifier)); } parameters.Sort(new QueryParameterComparer()); normalizedUrl = string.Format("{0}://{1}", url.Scheme, url.Host); if (!((url.Scheme == "http" && url.Port == 80) || (url.Scheme == "https" && url.Port == 443))) { normalizedUrl += ":" + url.Port; } normalizedUrl += url.AbsolutePath; normalizedRequestParameters = NormalizeRequestParameters(parameters); var signatureBase = new StringBuilder(); signatureBase.AppendFormat("{0}&", httpMethod.ToUpper()); signatureBase.AppendFormat("{0}&", UrlEncode(normalizedUrl)); signatureBase.AppendFormat("{0}", UrlEncode(normalizedRequestParameters)); #if DEBUG_API Debug.WriteLine("Signature Base: " + signatureBase.ToString()); Debug.WriteLine("normalizedRequestParameters: " + normalizedRequestParameters); #endif var hmacsha1 = new HMACSHA1 { Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(_consumerSecret), string.IsNullOrEmpty(token.Secret) ? "" : UrlEncode(token.Secret))) }; byte[] dataBuffer = Encoding.ASCII.GetBytes(signatureBase.ToString()); byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer); return(Convert.ToBase64String(hashBytes)); }