Exemple #1
0
        public bool IsValid(ImageDestination destination)
        {
            ImageUploaderService service = UploaderFactory.GetImageUploaderServiceByEnum(destination);

            if (service != null)
            {
                return(service.CheckConfig(this));
            }

            switch (destination)
            {
            case ImageDestination.ImageShack:
                return(ImageShackSettings != null && !string.IsNullOrEmpty(ImageShackSettings.Auth_token));

            case ImageDestination.TinyPic:
                return(TinyPicAccountType == AccountType.Anonymous || !string.IsNullOrEmpty(TinyPicRegistrationCode));

            case ImageDestination.Flickr:
                return(!string.IsNullOrEmpty(FlickrAuthInfo.Token));

            case ImageDestination.Photobucket:
                return(PhotobucketAccountInfo != null && OAuthInfo.CheckOAuth(PhotobucketOAuthInfo));

            case ImageDestination.Picasa:
                return(OAuth2Info.CheckOAuth(PicasaOAuth2Info));

            case ImageDestination.Twitter:
                return(TwitterOAuthInfoList != null && TwitterOAuthInfoList.IsValidIndex(TwitterSelectedAccount) && OAuthInfo.CheckOAuth(TwitterOAuthInfoList[TwitterSelectedAccount]));

            case ImageDestination.Chevereto:
                return(CheveretoUploader != null && !string.IsNullOrEmpty(CheveretoUploader.UploadURL) && !string.IsNullOrEmpty(CheveretoUploader.APIKey));

            case ImageDestination.CustomImageUploader:
                return(CustomUploadersList != null && CustomUploadersList.IsValidIndex(CustomImageUploaderSelected));
            }

            return(true);
        }
Exemple #2
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, URLHelper.URLEncode(callback));
                }

                if (args[ParameterTokenSecret] != null)
                {
                    oauth.AuthSecret = args[ParameterTokenSecret];
                }
            }

            return(url);
        }
        private void FlickrAuthOpen()
        {
            try
            {
                OAuthInfo oauth = new OAuthInfo(APIKeys.FlickrKey, APIKeys.FlickrSecret);

                string url = new FlickrUploader(oauth).GetAuthorizationURL();

                if (!string.IsNullOrEmpty(url))
                {
                    Config.FlickrOAuthInfo = oauth;
                    URLHelpers.OpenURL(url);
                    DebugHelper.WriteLine("FlickrAuthOpen - Authorization URL is opened: " + url);
                }
                else
                {
                    DebugHelper.WriteLine("FlickrAuthOpen - Authorization URL is empty.");
                }
            }
            catch (Exception ex)
            {
                ex.ShowError();
            }
        }
Exemple #4
0
        public bool IsValid(FileDestination destination)
        {
            switch (destination)
            {
            case FileDestination.Dropbox:
                return(OAuth2Info.CheckOAuth(DropboxOAuth2Info));

            case FileDestination.Copy:
                return(OAuthInfo.CheckOAuth(CopyOAuthInfo));

            case FileDestination.GoogleDrive:
                return(OAuth2Info.CheckOAuth(GoogleDriveOAuth2Info));

            case FileDestination.SendSpace:
                return(SendSpaceAccountType == AccountType.Anonymous || (!string.IsNullOrEmpty(SendSpaceUsername) && !string.IsNullOrEmpty(SendSpacePassword)));

            case FileDestination.Minus:
                return(MinusConfig != null && MinusConfig.MinusUser != null);

            case FileDestination.Box:
                return(OAuth2Info.CheckOAuth(BoxOAuth2Info));

            case FileDestination.Ge_tt:
                return(Ge_ttLogin != null && !string.IsNullOrEmpty(Ge_ttLogin.AccessToken));

            case FileDestination.Localhostr:
                return(!string.IsNullOrEmpty(LocalhostrEmail) && !string.IsNullOrEmpty(LocalhostrPassword));

            case FileDestination.CustomFileUploader:
                return(CustomUploadersList != null && CustomUploadersList.IsValidIndex(CustomFileUploaderSelected));

            case FileDestination.FTP:
                return(FTPAccountList != null && FTPAccountList.IsValidIndex(FTPSelectedFile));

            case FileDestination.SharedFolder:
                return(LocalhostAccountList != null && LocalhostAccountList.IsValidIndex(LocalhostSelectedFiles));

            case FileDestination.Email:
                return(!string.IsNullOrEmpty(EmailSmtpServer) && EmailSmtpPort > 0 && !string.IsNullOrEmpty(EmailFrom) && !string.IsNullOrEmpty(EmailPassword));

            case FileDestination.Jira:
                return(OAuthInfo.CheckOAuth(JiraOAuthInfo));

            case FileDestination.Mega:
                return(MegaAuthInfos != null && MegaAuthInfos.Email != null && MegaAuthInfos.Hash != null && MegaAuthInfos.PasswordAesKey != null);

            case FileDestination.Pushbullet:
                return(PushbulletSettings != null && !string.IsNullOrEmpty(PushbulletSettings.UserAPIKey) && PushbulletSettings.DeviceList != null &&
                       PushbulletSettings.DeviceList.IsValidIndex(PushbulletSettings.SelectedDevice));

            case FileDestination.OwnCloud:
                return(!string.IsNullOrEmpty(OwnCloudHost) && !string.IsNullOrEmpty(OwnCloudUsername) && !string.IsNullOrEmpty(OwnCloudPassword));

            case FileDestination.MediaFire:
                return(!string.IsNullOrEmpty(MediaFireUsername) && !string.IsNullOrEmpty(MediaFirePassword));

            case FileDestination.Lambda:
                return(LambdaSettings != null && !string.IsNullOrEmpty(LambdaSettings.UserAPIKey));
            }

            return(true);
        }
Exemple #5
0
        public bool IsValid(ImageDestination destination)
        {
            switch (destination)
            {
            case ImageDestination.Imgur:
                return(ImgurAccountType == AccountType.Anonymous || OAuth2Info.CheckOAuth(ImgurOAuth2Info));

            case ImageDestination.ImageShack:
                return(ImageShackSettings != null && !string.IsNullOrEmpty(ImageShackSettings.Auth_token));

            case ImageDestination.TinyPic:
                return(TinyPicAccountType == AccountType.Anonymous || !string.IsNullOrEmpty(TinyPicRegistrationCode));

            case ImageDestination.Flickr:
                return(!string.IsNullOrEmpty(FlickrAuthInfo.Token));

            case ImageDestination.Photobucket:
                return(PhotobucketAccountInfo != null && OAuthInfo.CheckOAuth(PhotobucketOAuthInfo));

            case ImageDestination.Picasa:
                return(OAuth2Info.CheckOAuth(PicasaOAuth2Info));

            case ImageDestination.Twitter:
                return(TwitterOAuthInfoList != null && TwitterOAuthInfoList.IsValidIndex(TwitterSelectedAccount) && OAuthInfo.CheckOAuth(TwitterOAuthInfoList[TwitterSelectedAccount]));

            case ImageDestination.CustomImageUploader:
                return(CustomUploadersList != null && CustomUploadersList.IsValidIndex(CustomImageUploaderSelected));
            }

            return(true);
        }
Exemple #6
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);
        }
Exemple #7
0
        public bool IsValid(FileDestination destination)
        {
            FileUploaderService service = UploaderFactory.GetFileUploaderServiceByEnum(destination);

            if (service != null)
            {
                return(service.CheckConfig(this));
            }

            switch (destination)
            {
            case FileDestination.FTP:
                return(FTPAccountList != null && FTPAccountList.IsValidIndex(FTPSelectedFile));

            case FileDestination.OneDrive:
                return(OAuth2Info.CheckOAuth(OneDriveOAuth2Info));

            case FileDestination.GoogleDrive:
                return(OAuth2Info.CheckOAuth(GoogleDriveOAuth2Info));

            case FileDestination.Box:
                return(OAuth2Info.CheckOAuth(BoxOAuth2Info));

            case FileDestination.Mega:
                return(MegaAuthInfos != null && MegaAuthInfos.Email != null && MegaAuthInfos.Hash != null && MegaAuthInfos.PasswordAesKey != null);

            case FileDestination.AmazonS3:
                return(AmazonS3Settings != null && !string.IsNullOrEmpty(AmazonS3Settings.AccessKeyID) && !string.IsNullOrEmpty(AmazonS3Settings.SecretAccessKey) &&
                       !string.IsNullOrEmpty(AmazonS3Settings.Bucket) && AmazonS3.GetCurrentRegion(AmazonS3Settings) != AmazonS3.UnknownEndpoint);

            case FileDestination.OwnCloud:
                return(!string.IsNullOrEmpty(OwnCloudHost) && !string.IsNullOrEmpty(OwnCloudUsername) && !string.IsNullOrEmpty(OwnCloudPassword));

            case FileDestination.MediaFire:
                return(!string.IsNullOrEmpty(MediaFireUsername) && !string.IsNullOrEmpty(MediaFirePassword));

            case FileDestination.Pushbullet:
                return(PushbulletSettings != null && !string.IsNullOrEmpty(PushbulletSettings.UserAPIKey) && PushbulletSettings.DeviceList != null &&
                       PushbulletSettings.DeviceList.IsValidIndex(PushbulletSettings.SelectedDevice));

            case FileDestination.SendSpace:
                return(SendSpaceAccountType == AccountType.Anonymous || (!string.IsNullOrEmpty(SendSpaceUsername) && !string.IsNullOrEmpty(SendSpacePassword)));

            case FileDestination.Minus:
                return(MinusConfig != null && MinusConfig.MinusUser != null);

            case FileDestination.Ge_tt:
                return(Ge_ttLogin != null && !string.IsNullOrEmpty(Ge_ttLogin.AccessToken));

            case FileDestination.Localhostr:
                return(!string.IsNullOrEmpty(LocalhostrEmail) && !string.IsNullOrEmpty(LocalhostrPassword));

            case FileDestination.Jira:
                return(OAuthInfo.CheckOAuth(JiraOAuthInfo));

            case FileDestination.Lambda:
                return(LambdaSettings != null && !string.IsNullOrEmpty(LambdaSettings.UserAPIKey));

            case FileDestination.Pomf:
                return(PomfUploader != null && !string.IsNullOrEmpty(PomfUploader.UploadURL));

            case FileDestination.Sul:
                return(!string.IsNullOrEmpty(SulAPIKey));

            case FileDestination.Seafile:
                return(!string.IsNullOrEmpty(SeafileAPIURL) && !string.IsNullOrEmpty(SeafileAuthToken) && !string.IsNullOrEmpty(SeafileRepoID));

            case FileDestination.SharedFolder:
                return(LocalhostAccountList != null && LocalhostAccountList.IsValidIndex(LocalhostSelectedFiles));

            case FileDestination.Email:
                return(!string.IsNullOrEmpty(EmailSmtpServer) && EmailSmtpPort > 0 && !string.IsNullOrEmpty(EmailFrom) && !string.IsNullOrEmpty(EmailPassword));

            case FileDestination.CustomFileUploader:
                return(CustomUploadersList != null && CustomUploadersList.IsValidIndex(CustomFileUploaderSelected));
            }

            return(true);
        }
Exemple #8
0
 public TwitterTweetForm(OAuthInfo oauth) : this()
 {
     AuthInfo = oauth;
 }
        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);
                }
            }
        }
Exemple #10
0
 public static string GenerateQuery(string url, Dictionary <string, string> args, HttpMethod httpMethod, OAuthInfo oauth)
 {
     return(GenerateQuery(url, args, httpMethod, oauth, out _));
 }
Exemple #11
0
        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;
        }
Exemple #12
0
        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;
        }
Exemple #13
0
 protected bool GetAccessToken(string accessTokenURL, OAuthInfo authInfo, HttpMethod httpMethod = HttpMethod.GET)
 {
     return GetAccessTokenEx(accessTokenURL, authInfo, httpMethod) != 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 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 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);
            }
        }
Exemple #17
0
        public bool IsValid(URLSharingServices destination)
        {
            switch (destination)
            {
            case URLSharingServices.Email:
                return(!string.IsNullOrEmpty(EmailSmtpServer) && EmailSmtpPort > 0 && !string.IsNullOrEmpty(EmailFrom) && !string.IsNullOrEmpty(EmailPassword));

            case URLSharingServices.Twitter:
                return(TwitterOAuthInfoList != null && TwitterOAuthInfoList.IsValidIndex(TwitterSelectedAccount) && OAuthInfo.CheckOAuth(TwitterOAuthInfoList[TwitterSelectedAccount]));

            case URLSharingServices.Pushbullet:
                return(PushbulletSettings != null && !string.IsNullOrEmpty(PushbulletSettings.UserAPIKey) && PushbulletSettings.DeviceList != null &&
                       PushbulletSettings.DeviceList.IsValidIndex(PushbulletSettings.SelectedDevice));
            }

            return(true);
        }
Exemple #18
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);
        }
Exemple #19
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);
 }
Exemple #20
0
        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);
        }
Exemple #21
0
 public TwitterTweetForm(OAuthInfo oauth) : this()
 {
     AuthInfo = oauth;
 }
        private void TwitterAuthClear()
        {
            if (CheckTwitterAccounts())
            {
                OAuthInfo oauth = new OAuthInfo();

                OAuthInfo oauth2 = GetSelectedTwitterAccount();

                if (oauth2 != null)
                {
                    oauth.Description = oauth2.Description;
                }

                Config.TwitterOAuthInfoList[Config.TwitterSelectedAccount] = oauth;
            }
        }
Exemple #23
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 = URLHelper.URLEncode(Convert.ToBase64String(signatureData));

            return(string.Format("{0}?{1}&{2}={3}", normalizedUrl, normalizedParameters, ParameterSignature, signature));
        }
Exemple #24
0
 public TwitterTweetForm(OAuthInfo oauth, string message) : this(oauth)
 {
     Message = message;
 }
Exemple #25
0
 protected bool GetAccessToken(string accessTokenURL, OAuthInfo authInfo, HttpMethod httpMethod = HttpMethod.GET)
 {
     return(GetAccessTokenEx(accessTokenURL, authInfo, httpMethod) != null);
 }
Exemple #26
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;
        }
Exemple #27
0
 public TwitterTweetForm(OAuthInfo oauth, string message) : this(oauth)
 {
     Message = message;
 }
Exemple #28
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;
        }