Exemplo n.º 1
0
        // We need the user to go on the Twitter Website to authorize our application
        private void GoToTwitterCaptchaPage(ITemporaryCredentials applicationCredentials)
        {
            var url = CredentialsCreator.GetAuthorizationURL(applicationCredentials);

            Console.WriteLine("Please go on {0}, to accept the application and get the captcha.", url);
            Process.Start(url.ToString());
        }
Exemplo n.º 2
0
        public ITwitterQuery Create(string queryURL, HttpMethod httpMethod, ITemporaryCredentials temporaryCredentials)
        {
            var twitterQuery = Create(queryURL, httpMethod);

            twitterQuery.TemporaryCredentials = temporaryCredentials;
            return(twitterQuery);
        }
Exemplo n.º 3
0
        // Step 2 - Generate User Credentials
        public IOAuthCredentials GetCredentialsFromVerifierCode(string verifierCode, ITemporaryCredentials temporaryCredentials)
        {
            var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_verifier", verifierCode, true, true, false);
            var response          = _twitterRequester.ExecuteQueryWithTemporaryCredentials(Resources.OAuthRequestAccessToken, HttpMethod.POST, temporaryCredentials: temporaryCredentials, headers: new[] { callbackParameter });

            if (response == null)
            {
                return(null);
            }

            Match responseInformation = Regex.Match(response, Resources.OAuthTokenAccessRegex);

            if (responseInformation.Groups["oauth_token"] == null || responseInformation.Groups["oauth_token_secret"] == null)
            {
                return(null);
            }

            var credentials = _credentialsFactory.CreateOAuthCredentials(
                responseInformation.Groups["oauth_token"].Value,
                responseInformation.Groups["oauth_token_secret"].Value,
                temporaryCredentials.ConsumerKey,
                temporaryCredentials.ConsumerSecret);

            return(credentials);
        }
Exemplo n.º 4
0
        public IOAuthCredentials GenerateToken(ITemporaryCredentials temporaryCredentials)
        {
            var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_verifier", temporaryCredentials.VerifierCode, true, true, false);

            try
            {
                var response = _twitterRequestHandler.ExecuteQueryWithTemporaryCredentials(Resources.OAuthRequestAccessToken, HttpMethod.POST, temporaryCredentials, new[] { callbackParameter });
                if (response == null)
                {
                    return(null);
                }

                Match responseInformation = Regex.Match(response, "oauth_token=(?<oauth_token>(?:\\w|\\-)*)&oauth_token_secret=(?<oauth_token_secret>(?:\\w)*)&user_id=(?<user_id>(?:\\d)*)&screen_name=(?<screen_name>(?:\\w)*)");

                var credentials = new OAuthCredentials();
                credentials.AccessToken       = responseInformation.Groups["oauth_token"].Value;
                credentials.AccessTokenSecret = responseInformation.Groups["oauth_token_secret"].Value;
                credentials.ConsumerKey       = temporaryCredentials.ConsumerKey;
                credentials.ConsumerSecret    = temporaryCredentials.ConsumerSecret;

                return(credentials);
            }
            catch (TwitterException ex)
            {
                LogExceptionOrThrow(ex);
            }

            return(null);
        }
Exemplo n.º 5
0
        public string GetAuthorizationURL(ITemporaryCredentials temporaryCredentials, string callbackURL)
        {
            try
            {
                var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_callback", callbackURL, true, true, false);
                var requestTokenResponse = _twitterRequestHandler.ExecuteQueryWithTemporaryCredentials(Resources.OAuthRequestToken, HttpMethod.POST, temporaryCredentials, new[] {callbackParameter});

                if (!string.IsNullOrEmpty(requestTokenResponse) && requestTokenResponse != Resources.OAuthRequestToken)
                {
                    Match tokenInformation = Regex.Match(requestTokenResponse, Resources.OAuthTokenRequestRegex);

                    bool callbackConfirmed = Boolean.Parse(tokenInformation.Groups["oauth_callback_confirmed"].Value);
                    if (!callbackConfirmed)
                    {
                        return null;
                    }

                    temporaryCredentials.AuthorizationKey = tokenInformation.Groups["oauth_token"].Value;
                    temporaryCredentials.AuthorizationSecret = tokenInformation.Groups["oauth_token_secret"].Value;

                    return String.Format("{0}?oauth_token={1}", Resources.OAuthRequestAuthorize, temporaryCredentials.AuthorizationKey);
                }
            }
            catch (TwitterException ex)
            {
                LogExceptionOrThrow(ex);
            }

            return null;
        }
Exemplo n.º 6
0
        public string GetAuthorizationURL(ITemporaryCredentials temporaryCredentials, string callbackURL)
        {
            try
            {
                var callbackParameter    = _oAuthWebRequestGenerator.GenerateParameter("oauth_callback", callbackURL, true, true, false);
                var requestTokenResponse = _twitterRequestHandler.ExecuteQueryWithTemporaryCredentials(Resources.OAuthRequestToken, HttpMethod.POST, temporaryCredentials, new[] { callbackParameter });

                if (!string.IsNullOrEmpty(requestTokenResponse) && requestTokenResponse != Resources.OAuthRequestToken)
                {
                    Match tokenInformation = Regex.Match(requestTokenResponse, Resources.OAuthTokenRequestRegex);

                    bool callbackConfirmed = Boolean.Parse(tokenInformation.Groups["oauth_callback_confirmed"].Value);
                    if (!callbackConfirmed)
                    {
                        return(null);
                    }

                    temporaryCredentials.AuthorizationKey    = tokenInformation.Groups["oauth_token"].Value;
                    temporaryCredentials.AuthorizationSecret = tokenInformation.Groups["oauth_token_secret"].Value;

                    return(String.Format("{0}?oauth_token={1}", Resources.OAuthRequestAuthorize, temporaryCredentials.AuthorizationKey));
                }
            }
            catch (TwitterException ex)
            {
                LogExceptionOrThrow(ex);
            }

            return(null);
        }
Exemplo n.º 7
0
        public string ExecuteQueryWithSpecificParametersAndTemporaryCredentials(
            string url,
            HttpMethod httpMethod,
            IEnumerable <IOAuthQueryParameter> parameters,
            ITemporaryCredentials temporaryCredentials)
        {
            var queryParameters = _oAuthWebRequestGenerator.GenerateApplicationParameters(temporaryCredentials, parameters);

            return(ExecuteQueryWithSpecificParameters(url, httpMethod, queryParameters));
        }
        public HttpWebRequest GetQueryWebRequestWithTemporaryCredentials(
            string url,
            HttpMethod httpMethod,
            ITemporaryCredentials temporaryCredentials,
            IEnumerable <IOAuthQueryParameter> parameters = null)
        {
            var headers = _webRequestGenerator.GenerateApplicationParameters(temporaryCredentials, parameters);

            return(GetQueryWebRequest(url, httpMethod, headers));
        }
Exemplo n.º 9
0
        //private IDisposable _oauthCallbackServer;
        //private string _callbackListenerURI;

        public WorkerRole()
        {
            _applicationCredentials 
                = CredentialsCreator.GenerateApplicationCredentials("UrvdMoVknBFnfO0Y3PsxdAGSn", "sh9YkoVhW4bRyvcKr4Bz4WOIPA05TRwixjMr9hwDz0DTv0v7wX");

            _userCredentials
                = TwitterCredentials.CreateCredentials(
                    "69378065-9cXZ3wy8X1ui35hYcHhsjIR7OdjuaUFo5k92vr3E4", "IOn5rWh8P8IOmEZx1Wd9hacKFchYhblVEAnRyG6dqy8Pz", 
                    "UrvdMoVknBFnfO0Y3PsxdAGSn", "sh9YkoVhW4bRyvcKr4Bz4WOIPA05TRwixjMr9hwDz0DTv0v7wX"
                );

            TwitterCredentials.SetCredentials(_userCredentials);
        }
Exemplo n.º 10
0
        public IOAuthCredentials GetCredentialsFromCallbackURL(string callbackURL, ITemporaryCredentials temporaryCredentials)
        {
            Match urlInformation = Regex.Match(callbackURL, Resources.OAuthToken_GetVerifierCode_Regex);

            String responseOAuthToken = urlInformation.Groups["oauth_token"].Value;
            String verifierCode       = urlInformation.Groups["oauth_verifier"].Value;

            // Check that the callback URL response passed in is for our current credentials....
            if (String.Equals(responseOAuthToken, temporaryCredentials.AuthorizationKey))
            {
                GetCredentialsFromVerifierCode(verifierCode, temporaryCredentials);
            }

            return(null);
        }
        public IEnumerable <IOAuthQueryParameter> GenerateApplicationParameters(ITemporaryCredentials temporaryCredentials, IEnumerable <IOAuthQueryParameter> additionalParameters = null)
        {
            var headers = GenerateConsumerParameters(temporaryCredentials).ToList();

            // Add Header for authenticated connection to a Twitter Application
            if (temporaryCredentials != null && !String.IsNullOrEmpty(temporaryCredentials.AuthorizationKey) && !String.IsNullOrEmpty(temporaryCredentials.AuthorizationSecret))
            {
                headers.Add(new OAuthQueryParameter("oauth_token", StringFormater.UrlEncode(temporaryCredentials.AuthorizationKey), true, true, false));
                headers.Add(new OAuthQueryParameter("oauth_token_secret", StringFormater.UrlEncode(temporaryCredentials.AuthorizationSecret), false, false, true));
            }
            else
            {
                headers.Add(new OAuthQueryParameter("oauth_token", "", false, false, true));
            }

            if (additionalParameters != null)
            {
                headers.AddRange(additionalParameters);
            }

            return(headers);
        }
Exemplo n.º 12
0
        // On the Twitter website the user will get a captcha that he will need to enter in the application
        private void GenerateCredentialsAndLogin(string captcha, ITemporaryCredentials applicationCredentials)
        {
            var newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(captcha, applicationCredentials);

            // And now the user is logged in!
            TwitterCredentials.SetCredentials(newCredentials);

            var loggedUser = User.GetLoggedUser();

            Console.WriteLine("You are logged as {0}", loggedUser.ScreenName);

            if (loggedUser.ScreenName != "")
            {
                CurrentStatusCount.Text = "Authorised";
                accesskey.Text          = newCredentials.AccessToken;
                accesskeySecret.Text    = newCredentials.AccessTokenSecret;
            }
            else
            {
                CurrentStatusCount.Text = "Not Authorised";
                accesskey.Text          = "";
                accesskeySecret.Text    = "";
            }
        }
Exemplo n.º 13
0
 // Step 2
 public static IOAuthCredentials GetCredentialsFromVerifierCode(string verifierCode, ITemporaryCredentials temporaryCredentials)
 {
     return _credentialsCreator.GetCredentialsFromVerifierCode(verifierCode, temporaryCredentials);
 }
Exemplo n.º 14
0
 public ITwitterQuery Create(string queryURL, HttpMethod httpMethod, ITemporaryCredentials temporaryCredentials)
 {
     var twitterQuery = Create(queryURL, httpMethod);
     twitterQuery.TemporaryCredentials = temporaryCredentials;
     return twitterQuery;
 }
Exemplo n.º 15
0
        public IOAuthCredentials GetCredentialsFromCallbackURL(string callbackURL, ITemporaryCredentials temporaryCredentials)
        {
            Match urlInformation = Regex.Match(callbackURL, Resources.OAuthToken_GetVerifierCode_Regex);

            String responseOAuthToken = urlInformation.Groups["oauth_token"].Value;
            String verifierCode = urlInformation.Groups["oauth_verifier"].Value;

            // Check that the callback URL response passed in is for our current credentials....
            if (String.Equals(responseOAuthToken, temporaryCredentials.AuthorizationKey))
            {
                GetCredentialsFromVerifierCode(verifierCode, temporaryCredentials);
            }

            return null;
        }
Exemplo n.º 16
0
 // Step 1 - Generate Authorization URL
 public string GetPinCodeAuthorizationURL(ITemporaryCredentials temporaryCredentials)
 {
     return GetAuthorizationURL(temporaryCredentials, Resources.OAuth_PINCode_CallbackURL);
 }
Exemplo n.º 17
0
 // Step 1 - Code
 public static string GetAuthorizationURL(ITemporaryCredentials temporaryCredentials)
 {
     return(_webTokenCreator.GetPinCodeAuthorizationURL(temporaryCredentials));
 }
Exemplo n.º 18
0
 internal void OnAuthorizeAccount(object sender, RoutedEventArgs e)
 {
     if (_isAuthInProgress)
         return;
     _isAuthInProgress = true;
     _tmpAppCredentials = CredentialsCreator.GenerateApplicationCredentials(TwitterAccountAuth.ConsumerKey, TwitterAccountAuth.ConsumerSecret);
     var uri = CredentialsCreator.GetAuthorizationURL(_tmpAppCredentials);
     Process.Start(uri);
 }
Exemplo n.º 19
0
        public string ExecuteQueryWithTemporaryCredentials(string url, HttpMethod httpMethod, ITemporaryCredentials temporaryCredentials, IEnumerable <IOAuthQueryParameter> parameters)
        {
            var webRequest = _twitterRequestGenerator.GetQueryWebRequestWithTemporaryCredentials(url, httpMethod, temporaryCredentials, parameters);

            return(_webRequestExecutor.ExecuteWebRequest(webRequest));
        }
Exemplo n.º 20
0
        public IOAuthCredentials GenerateToken(ITemporaryCredentials temporaryCredentials)
        {
            var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_verifier", temporaryCredentials.VerifierCode, true, true, false);

            try
            {
                var response = _twitterRequestHandler.ExecuteQueryWithTemporaryCredentials(Resources.OAuthRequestAccessToken, HttpMethod.POST, temporaryCredentials, new[] { callbackParameter });
                if (response == null)
                {
                    return null;
                }

                Match responseInformation = Regex.Match(response, "oauth_token=(?<oauth_token>(?:\\w|\\-)*)&oauth_token_secret=(?<oauth_token_secret>(?:\\w)*)&user_id=(?<user_id>(?:\\d)*)&screen_name=(?<screen_name>(?:\\w)*)");

                var credentials = new OAuthCredentials();
                credentials.AccessToken = responseInformation.Groups["oauth_token"].Value;
                credentials.AccessTokenSecret = responseInformation.Groups["oauth_token_secret"].Value;
                credentials.ConsumerKey = temporaryCredentials.ConsumerKey;
                credentials.ConsumerSecret = temporaryCredentials.ConsumerSecret;

                return credentials;
            }
            catch (TwitterException ex)
            {
                LogExceptionOrThrow(ex);
            }

            return null;
        }
Exemplo n.º 21
0
 public string ExecuteQuery(string url, HttpMethod httpMethod, ITemporaryCredentials temporaryCredentials)
 {
     return(ExecuteQueryWithSpecificParameters(url, httpMethod, _oAuthWebRequestGenerator.GenerateApplicationParameters(temporaryCredentials)));
 }
Exemplo n.º 22
0
 // Step 1 - Code
 public static string GetAuthorizationURL(ITemporaryCredentials temporaryCredentials)
 {
     return _webTokenCreator.GetPinCodeAuthorizationURL(temporaryCredentials);
 }
Exemplo n.º 23
0
 public static IOAuthCredentials GetCredentialsFromCallbackURL(string callbackURL, ITemporaryCredentials temporaryCredentials)
 {
     string verifierCode = _webTokenCreator.GetVerifierCodeFromCallbackURL(callbackURL);
     return GetCredentialsFromVerifierCode(verifierCode, temporaryCredentials);
 }
Exemplo n.º 24
0
        private void GetPinClick(object sender, RoutedEventArgs e)
        {
            applicationCredentials = CreateApplicationCredentials(consumerkey.Text, consumerkeySecret.Text);

            GoToTwitterCaptchaPage(applicationCredentials);
        }
Exemplo n.º 25
0
 // Step 1 - Callback URL
 public static string GetAuthorizationURLForCallback(ITemporaryCredentials temporaryCredentials, string callbackURL)
 {
     return(_webTokenCreator.GetAuthorizationURL(temporaryCredentials, callbackURL));
 }
        public IEnumerable<IOAuthQueryParameter> GenerateApplicationParameters(ITemporaryCredentials temporaryCredentials, IEnumerable<IOAuthQueryParameter> additionalParameters = null)
        {
            var headers = GenerateConsumerParameters(temporaryCredentials).ToList();

            // Add Header for authenticated connection to a Twitter Application
            if (temporaryCredentials != null && !String.IsNullOrEmpty(temporaryCredentials.AuthorizationKey) && !String.IsNullOrEmpty(temporaryCredentials.AuthorizationSecret))
            {
                headers.Add(new OAuthQueryParameter("oauth_token", StringFormater.UrlEncode(temporaryCredentials.AuthorizationKey), true, true, false));
                headers.Add(new OAuthQueryParameter("oauth_token_secret", StringFormater.UrlEncode(temporaryCredentials.AuthorizationSecret), false, false, true));
            }
            else
            {
                headers.Add(new OAuthQueryParameter("oauth_token", "", false, false, true));
            }

            if (additionalParameters != null)
            {
                headers.AddRange(additionalParameters);
            }

            return headers;
        }
Exemplo n.º 27
0
 // Step 2
 public static IOAuthCredentials GetCredentialsFromVerifierCode(string verifierCode, ITemporaryCredentials temporaryCredentials)
 {
     return(_credentialsCreator.GetCredentialsFromVerifierCode(verifierCode, temporaryCredentials));
 }
Exemplo n.º 28
0
 public IOAuthCredentials GetCredentialsFromVerifierCode(string verifierCode, ITemporaryCredentials temporaryCredentials)
 {
     temporaryCredentials.VerifierCode = verifierCode;
     return(GenerateToken(temporaryCredentials));
 }
Exemplo n.º 29
0
        public static IOAuthCredentials GetCredentialsFromCallbackURL(string callbackURL, ITemporaryCredentials temporaryCredentials)
        {
            string verifierCode = _webTokenCreator.GetVerifierCodeFromCallbackURL(callbackURL);

            return(GetCredentialsFromVerifierCode(verifierCode, temporaryCredentials));
        }
Exemplo n.º 30
0
 // Step 1 - Generate Authorization URL
 public string GetPinCodeAuthorizationURL(ITemporaryCredentials temporaryCredentials)
 {
     return(GetAuthorizationURL(temporaryCredentials, Resources.OAuth_PINCode_CallbackURL));
 }
Exemplo n.º 31
0
        public string ExecuteQueryWithTemporaryCredentials(string queryURL, HttpMethod httpMethod, ITemporaryCredentials temporaryCredentials, IEnumerable <IOAuthQueryParameter> queryParameters)
        {
            CleanupQueryURL(ref queryURL);

            var twitterQuery = _twitterQueryFactory.Create(queryURL, httpMethod, temporaryCredentials);

            twitterQuery.QueryParameters = queryParameters;

            _tweetinviEvents.RaiseBeforeQueryExecute(new QueryBeforeExecuteEventArgs(twitterQuery));

            var result = _twitterRequester.ExecuteQuery(twitterQuery);

            _tweetinviEvents.RaiseAfterQueryExecuted(new QueryAfterExecuteEventArgs(twitterQuery, result));

            return(result);
        }
Exemplo n.º 32
0
 public IOAuthCredentials GetCredentialsFromVerifierCode(string verifierCode, ITemporaryCredentials temporaryCredentials)
 {
     temporaryCredentials.VerifierCode = verifierCode;
     return GenerateToken(temporaryCredentials);
 }
Exemplo n.º 33
0
 // Step 1 - Callback URL
 public static string GetAuthorizationURLForCallback(ITemporaryCredentials temporaryCredentials, string callbackURL)
 {
     return _webTokenCreator.GetAuthorizationURL(temporaryCredentials, callbackURL);
 }