public static string GetAuthorizationURL(string requestTokenResponse, OAuthInfo oauth, string authorizeURL, string callback = null) { string url = null; NameValueCollection args = HttpUtility.ParseQueryString(requestTokenResponse); if (args[ParameterToken] != null) { oauth.AuthToken = args[ParameterToken]; url = string.Format("{0}?{1}={2}", authorizeURL, ParameterToken, oauth.AuthToken); if (!string.IsNullOrEmpty(callback)) { url += string.Format("&{0}={1}", ParameterCallback, URLHelpers.URLEncode(callback)); } if (args[ParameterTokenSecret] != null) { oauth.AuthSecret = args[ParameterTokenSecret]; } } return(url); }
public Jira(string jiraBaseAddress, OAuthInfo oauth, string jiraIssuePrefix = null) { _jiraBaseAddress = jiraBaseAddress; AuthInfo = oauth; _jiraIssuePrefix = jiraIssuePrefix; InitUris(); }
public Copy(OAuthInfo oauth, CopyAccountInfo accountInfo) : this(oauth) { AccountInfo = accountInfo; }
public Copy(OAuthInfo oauth) { AuthInfo = oauth; }
public void PhotobucketAuthOpen() { try { OAuthInfo oauth = new OAuthInfo(APIKeys.PhotobucketConsumerKey, APIKeys.PhotobucketConsumerSecret); string url = new Photobucket(oauth).GetAuthorizationURL(); if (!string.IsNullOrEmpty(url)) { Config.PhotobucketOAuthInfo = oauth; URLHelpers.OpenURL(url); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), Resources.UploadersConfigForm_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public TwitSnapsUploader(string apiKey, OAuthInfo oauth) { APIKey = apiKey; AuthInfo = oauth; }
public static NameValueCollection ParseAccessTokenResponse(string accessTokenResponse, OAuthInfo oauth) { NameValueCollection args = HttpUtility.ParseQueryString(accessTokenResponse); if (args != null && args[ParameterToken] != null) { oauth.UserToken = args[ParameterToken]; if (args[ParameterTokenSecret] != null) { oauth.UserSecret = args[ParameterTokenSecret]; return args; } } return null; }
protected string GetAuthorizationURL(string requestTokenURL, string authorizeURL, OAuthInfo authInfo, Dictionary<string, string> customParameters = null, HttpMethod httpMethod = HttpMethod.GET) { string url = OAuthManager.GenerateQuery(requestTokenURL, customParameters, httpMethod, authInfo); string response = SendRequest(httpMethod, url); if (!string.IsNullOrEmpty(response)) { return OAuthManager.GetAuthorizationURL(response, authInfo, authorizeURL); } return null; }
public TwitterTweetForm(OAuthInfo oauth, string message) : this(oauth) { Message = message; }
public TwitterTweetForm(OAuthInfo oauth) : this() { AuthInfo = oauth; }
public void JiraAuthOpen() { try { OAuthInfo oauth = new OAuthInfo(APIKeys.JiraConsumerKey); oauth.SignatureMethod = OAuthInfo.OAuthInfoSignatureMethod.RSA_SHA1; oauth.ConsumerPrivateKey = Jira.PrivateKey; string url = new Jira(Config.JiraHost, oauth).GetAuthorizationURL(); if (!string.IsNullOrEmpty(url)) { Config.JiraOAuthInfo = oauth; URLHelpers.OpenURL(url); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), Resources.UploadersConfigForm_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void CopyAuthOpen() { try { OAuthInfo oauth = new OAuthInfo(APIKeys.CopyConsumerKey, APIKeys.CopyConsumerSecret); string url = new Copy(oauth).GetAuthorizationURL(); if (!string.IsNullOrEmpty(url)) { Config.CopyOAuthInfo = oauth; URLHelpers.OpenURL(url); DebugHelper.WriteLine("CopyAuthOpen - Authorization URL is opened: " + url); } else { DebugHelper.WriteLine("CopyAuthOpen - Authorization URL is empty."); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), Resources.UploadersConfigForm_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void TwitterAuthOpen() { if (CheckTwitterAccounts()) { try { OAuthInfo oauth = new OAuthInfo(APIKeys.TwitterConsumerKey, APIKeys.TwitterConsumerSecret); string url = new Twitter(oauth).GetAuthorizationURL(); if (!string.IsNullOrEmpty(url)) { oauth.Description = Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount].Description; Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount] = oauth; URLHelpers.OpenURL(url); DebugHelper.WriteLine("TwitterAuthOpen - Authorization URL is opened: " + url); } else { DebugHelper.WriteLine("TwitterAuthOpen - Authorization URL is empty."); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), Resources.UploadersConfigForm_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void TwitterAuthClear() { if (CheckTwitterAccounts()) { OAuthInfo oauth = new OAuthInfo(); OAuthInfo oauth2 = GetSelectedTwitterAccount(); if (oauth2 != null) { oauth.Description = oauth2.Description; } Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount] = oauth; } }
protected bool GetAccessToken(string accessTokenURL, OAuthInfo authInfo, HttpMethod httpMethod = HttpMethod.GET) { return GetAccessTokenEx(accessTokenURL, authInfo, httpMethod) != null; }
protected NameValueCollection GetAccessTokenEx(string accessTokenURL, OAuthInfo authInfo, HttpMethod httpMethod = HttpMethod.GET) { if (string.IsNullOrEmpty(authInfo.AuthToken) || string.IsNullOrEmpty(authInfo.AuthSecret)) { throw new Exception("Auth infos missing. Open Authorization URL first."); } string url = OAuthManager.GenerateQuery(accessTokenURL, null, httpMethod, authInfo); string response = SendRequest(httpMethod, url); if (!string.IsNullOrEmpty(response)) { return OAuthManager.ParseAccessTokenResponse(response, authInfo); } return null; }
private void btnTwitterAdd_Click(object sender, EventArgs e) { OAuthInfo oauth = new OAuthInfo(); Config.TwitterOAuthInfoList.Add(oauth); lbTwitterAccounts.Items.Add(oauth.Description); lbTwitterAccounts.SelectedIndex = lbTwitterAccounts.Items.Count - 1; TwitterUpdateSelected(); }
public static string GetAuthorizationURL(string requestTokenResponse, OAuthInfo oauth, string authorizeURL, string callback = null) { string url = null; NameValueCollection args = HttpUtility.ParseQueryString(requestTokenResponse); if (args[ParameterToken] != null) { oauth.AuthToken = args[ParameterToken]; url = string.Format("{0}?{1}={2}", authorizeURL, ParameterToken, oauth.AuthToken); if (!string.IsNullOrEmpty(callback)) { url += string.Format("&{0}={1}", ParameterCallback, URLHelpers.URLEncode(callback)); } if (args[ParameterTokenSecret] != null) { oauth.AuthSecret = args[ParameterTokenSecret]; } } return url; }
public static NameValueCollection ParseAccessTokenResponse(string accessTokenResponse, OAuthInfo oauth) { NameValueCollection args = HttpUtility.ParseQueryString(accessTokenResponse); if (args != null && args[ParameterToken] != null) { oauth.UserToken = args[ParameterToken]; if (args[ParameterTokenSecret] != null) { oauth.UserSecret = args[ParameterTokenSecret]; return(args); } } return(null); }
public static string GenerateQuery(string url, Dictionary<string, string> args, HttpMethod httpMethod, OAuthInfo oauth) { if (string.IsNullOrEmpty(oauth.ConsumerKey) || (string.IsNullOrEmpty(oauth.ConsumerSecret) && oauth.SignatureMethod == OAuthInfo.OAuthInfoSignatureMethod.HMAC_SHA1) || (oauth.ConsumerPrivateKey == null && oauth.SignatureMethod == OAuthInfo.OAuthInfoSignatureMethod.RSA_SHA1)) { throw new Exception("ConsumerKey or ConsumerSecret or ConsumerPrivateKey empty."); } Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add(ParameterVersion, oauth.OAuthVersion); parameters.Add(ParameterNonce, GenerateNonce()); parameters.Add(ParameterTimestamp, GenerateTimestamp()); parameters.Add(ParameterConsumerKey, oauth.ConsumerKey); switch (oauth.SignatureMethod) { case OAuthInfo.OAuthInfoSignatureMethod.HMAC_SHA1: parameters.Add(ParameterSignatureMethod, HMACSHA1SignatureType); break; case OAuthInfo.OAuthInfoSignatureMethod.RSA_SHA1: parameters.Add(ParameterSignatureMethod, RSASHA1SignatureType); break; default: throw new NotImplementedException("Unsupported signature method"); } string secret = null; if (!string.IsNullOrEmpty(oauth.UserToken) && !string.IsNullOrEmpty(oauth.UserSecret)) { secret = oauth.UserSecret; parameters.Add(ParameterToken, oauth.UserToken); } else if (!string.IsNullOrEmpty(oauth.AuthToken) && !string.IsNullOrEmpty(oauth.AuthSecret)) { secret = oauth.AuthSecret; parameters.Add(ParameterToken, oauth.AuthToken); if (!string.IsNullOrEmpty(oauth.AuthVerifier)) { parameters.Add(ParameterVerifier, oauth.AuthVerifier); } } if (args != null) { foreach (KeyValuePair<string, string> arg in args) { parameters[arg.Key] = arg.Value; } } string normalizedUrl = NormalizeUrl(url); string normalizedParameters = NormalizeParameters(parameters); string signatureBase = GenerateSignatureBase(httpMethod, normalizedUrl, normalizedParameters); byte[] signatureData; switch (oauth.SignatureMethod) { case OAuthInfo.OAuthInfoSignatureMethod.HMAC_SHA1: signatureData = GenerateSignature(signatureBase, oauth.ConsumerSecret, secret); break; case OAuthInfo.OAuthInfoSignatureMethod.RSA_SHA1: signatureData = GenerateSignatureRSASHA1(signatureBase, oauth.ConsumerPrivateKey); break; default: throw new NotImplementedException("Unsupported signature method"); } string signature = URLHelpers.URLEncode(Convert.ToBase64String(signatureData)); return string.Format("{0}?{1}&{2}={3}", normalizedUrl, normalizedParameters, ParameterSignature, signature); }
public static string GenerateQuery(string url, Dictionary <string, string> args, HttpMethod httpMethod, OAuthInfo oauth) { if (string.IsNullOrEmpty(oauth.ConsumerKey) || (string.IsNullOrEmpty(oauth.ConsumerSecret) && oauth.SignatureMethod == OAuthInfo.OAuthInfoSignatureMethod.HMAC_SHA1) || (oauth.ConsumerPrivateKey == null && oauth.SignatureMethod == OAuthInfo.OAuthInfoSignatureMethod.RSA_SHA1)) { throw new Exception("ConsumerKey or ConsumerSecret or ConsumerPrivateKey empty."); } Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add(ParameterVersion, oauth.OAuthVersion); parameters.Add(ParameterNonce, GenerateNonce()); parameters.Add(ParameterTimestamp, GenerateTimestamp()); parameters.Add(ParameterConsumerKey, oauth.ConsumerKey); switch (oauth.SignatureMethod) { case OAuthInfo.OAuthInfoSignatureMethod.HMAC_SHA1: parameters.Add(ParameterSignatureMethod, HMACSHA1SignatureType); break; case OAuthInfo.OAuthInfoSignatureMethod.RSA_SHA1: parameters.Add(ParameterSignatureMethod, RSASHA1SignatureType); break; default: throw new NotImplementedException("Unsupported signature method"); } string secret = null; if (!string.IsNullOrEmpty(oauth.UserToken) && !string.IsNullOrEmpty(oauth.UserSecret)) { secret = oauth.UserSecret; parameters.Add(ParameterToken, oauth.UserToken); } else if (!string.IsNullOrEmpty(oauth.AuthToken) && !string.IsNullOrEmpty(oauth.AuthSecret)) { secret = oauth.AuthSecret; parameters.Add(ParameterToken, oauth.AuthToken); if (!string.IsNullOrEmpty(oauth.AuthVerifier)) { parameters.Add(ParameterVerifier, oauth.AuthVerifier); } } if (args != null) { foreach (KeyValuePair <string, string> arg in args) { parameters[arg.Key] = arg.Value; } } string normalizedUrl = NormalizeUrl(url); string normalizedParameters = NormalizeParameters(parameters); string signatureBase = GenerateSignatureBase(httpMethod, normalizedUrl, normalizedParameters); byte[] signatureData; switch (oauth.SignatureMethod) { case OAuthInfo.OAuthInfoSignatureMethod.HMAC_SHA1: signatureData = GenerateSignature(signatureBase, oauth.ConsumerSecret, secret); break; case OAuthInfo.OAuthInfoSignatureMethod.RSA_SHA1: signatureData = GenerateSignatureRSASHA1(signatureBase, oauth.ConsumerPrivateKey); break; default: throw new NotImplementedException("Unsupported signature method"); } string signature = URLHelpers.URLEncode(Convert.ToBase64String(signatureData)); return(string.Format("{0}?{1}&{2}={3}", normalizedUrl, normalizedParameters, ParameterSignature, signature)); }
public Twitter(OAuthInfo oauth) { AuthInfo = oauth; }
public static bool CheckOAuth(OAuthInfo oauth) { return oauth != null && !string.IsNullOrEmpty(oauth.ConsumerKey) && ((!string.IsNullOrEmpty(oauth.ConsumerSecret) && oauth.SignatureMethod == OAuthInfoSignatureMethod.HMAC_SHA1) || oauth.ConsumerPrivateKey != null && oauth.SignatureMethod == OAuthInfoSignatureMethod.RSA_SHA1) && !string.IsNullOrEmpty(oauth.UserToken) && !string.IsNullOrEmpty(oauth.UserSecret); }