public TwitPicUploader(string key, OAuthInfo oauth)
 {
     APIKey = key;
     AuthInfo = oauth;
     TwitPicUploadType = TwitPicUploadType.UPLOAD_IMAGE_ONLY;
     ShowFull = false;
     TwitPicThumbnailMode = TwitPicThumbnailType.Thumb;
 }
Пример #2
0
        public Jira(string jiraBaseAddress, OAuthInfo oauth, string jiraIssuePrefix = null)
        {
            _jiraBaseAddress = jiraBaseAddress;
            AuthInfo = oauth;
            _jiraIssuePrefix = jiraIssuePrefix;

            InitUris();
        }
Пример #3
0
        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);
        }
Пример #4
0
 public Twitter(OAuthInfo oauth)
 {
     AuthInfo = oauth;
 }
Пример #5
0
        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));
        }
Пример #6
0
        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);
        }
Пример #7
0
        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;
        }
Пример #8
0
        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);
        }
Пример #9
0
 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);
 }
Пример #10
0
        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;
        }
Пример #11
0
 public TwitSnapsUploader(string apiKey, OAuthInfo oauth)
 {
     APIKey = apiKey;
     AuthInfo = oauth;
 }
Пример #12
0
 public Imgur_v2(AccountType uploadMethod, string anonymousKey, OAuthInfo oauth)
 {
     UploadMethod = uploadMethod;
     AnonymousKey = anonymousKey;
     AuthInfo = oauth;
 }
Пример #13
0
 public Copy(OAuthInfo oauth, CopyAccountInfo accountInfo)
     : this(oauth)
 {
     AccountInfo = accountInfo;
 }
Пример #14
0
 public Copy(OAuthInfo oauth)
 {
     AuthInfo = oauth;
 }
Пример #15
0
 public Photobucket(OAuthInfo oauth, PhotobucketAccountInfo accountInfo)
 {
     AuthInfo = oauth;
     AccountInfo = accountInfo;
 }
Пример #16
0
 public Photobucket(OAuthInfo oauth)
 {
     AuthInfo = oauth;
     AccountInfo = new PhotobucketAccountInfo();
 }
Пример #17
0
 public Imgur_v2(OAuthInfo oauth)
 {
     UploadMethod = AccountType.User;
     AuthInfo = oauth;
 }