public void userAuthentication()
        {
            OAuthTokenResponse tokenResponse = new OAuthTokenResponse();
            tokenResponse = Twitterizer.OAuthUtility.GetRequestToken(consumerKey, consumerSecret, callbackAddy);

            //Directs you to the authentication page of your Twitter account.
            string target = "http://twitter.com/oauth/authorize?oauth_token=" + tokenResponse.Token;
            try
            {
                System.Diagnostics.Process.Start(target);
                Console.Write("Please enter PIN: ");
                pin = Console.ReadLine();
                pin = Properties.Settings.Default.pin;
                tokenResponse2 = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, tokenResponse.Token, pin);

                //When the user is considered to be a valid user, he/she will be directed to the Tweet class which enables you to tweet a message.
                Tweet tweet = new Tweet();
                tweet.messageMenu();
            }
            catch (System.ComponentModel.Win32Exception noBrowser)
            {
                if (noBrowser.ErrorCode == -2147467259)
                    Console.WriteLine(noBrowser.Message);
            }
            catch (System.Exception other)
            {
                Console.WriteLine(other.Message);
            }
        }
Example #2
0
        public static Uri RegisterApplicationRequestUrl()
        {
            NanaTwitter.RequestToken = OAuthUtility.GetRequestToken(NanaTwitter.ConsumerKey,NanaTwitter.ConsumerSecret,"oob");
            Console.WriteLine(NanaTwitter.RequestToken.Token.ToString());
            Uri uri = OAuthUtility.BuildAuthorizationUri(NanaTwitter.RequestToken.Token);

            return uri;
        }
Example #3
0
        public static void CompleteAccountProvision(string accountName, OAuthTokenResponse RequestToken, string VerificationString)
        {
            OAuthTokenResponse accessToken = OAuthUtility.GetAccessToken(Twitter_ConsumerKey, Twitter_ConsumerSecret, RequestToken.Token, VerificationString);
            TwitterAccount account = new TwitterAccount(accountName, accessToken, VerificationString);

            TwitterAccounts.Add(account);

            AddAccountToDB(account);
        }
Example #4
0
        //
        // GET: UserAccount/Index
        public ActionResult Index(string id)
        {
            ViewBag.UserId = id;

            if (User != null && User.Identity.IsAuthenticated)
            {
                _token = Session["UserToken"] as OAuthTokenResponse;
            }

            return View();
        }
Example #5
0
        /// <summary>
        /// Allows OAuth applications to directly exchange Twitter usernames and passwords for OAuth access tokens and secrets.
        /// </summary>
        /// <param name="consumerKey">The consumer key.</param>
        /// <param name="consumerSecret">The consumer secret.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns>A <see cref="OAuthTokenResponse"/> instance.</returns>
        public static OAuthTokenResponse GetAccessTokens(string consumerKey, string consumerSecret, string username, string password)
        {
            if (string.IsNullOrEmpty(consumerKey))
            {
                throw new ArgumentNullException("consumerKey");
            }

            if (string.IsNullOrEmpty(consumerSecret))
            {
                throw new ArgumentNullException("consumerSecret");
            }

            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException("username");
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password");
            }

            OAuthTokenResponse response = new OAuthTokenResponse();

            try
            {
                WebRequestBuilder builder = new WebRequestBuilder(
                    new Uri("https://api.twitter.com/oauth/access_token"),
                    HTTPVerb.POST,
                    new OAuthTokens() { ConsumerKey = consumerKey, ConsumerSecret = consumerSecret });

                builder.Parameters.Add("x_auth_username", username);
                builder.Parameters.Add("x_auth_password", password);
                builder.Parameters.Add("x_auth_mode", "client_auth");

                string responseBody = new StreamReader(builder.ExecuteRequest().GetResponseStream()).ReadToEnd();

                response.Token = Regex.Match(responseBody, @"oauth_token=([^&]+)").Groups[1].Value;
                response.TokenSecret = Regex.Match(responseBody, @"oauth_token_secret=([^&]+)").Groups[1].Value;
                if (responseBody.Contains("user_id="))
                    response.UserId = long.Parse(Regex.Match(responseBody, @"user_id=([^&]+)").Groups[1].Value, CultureInfo.CurrentCulture);
                response.ScreenName = Regex.Match(responseBody, @"screen_name=([^&]+)").Groups[1].Value;
            }
            catch (WebException wex)
            {
                throw new TwitterizerException(wex.Message, wex);
            }

            return response;
        }
        public void Persist(
            OAuthTokenResponse me,
            string oauth_token,
            string oauth_verifier)
        {
            if (_clientInfo == null)
                GetUser();

            using (Database db = new MySqlDatabase())
            {
                ClientInfo ci = db.GetClientInfo(Util.UserId);

                db.UpdateSocialCredential(ci.ClientId, SocialConnector.Twitter, "twitterid", Convert.ToString(me.UserId));
                db.UpdateSocialCredential(ci.ClientId, SocialConnector.Twitter, "oauthtoken", oauth_token);
                db.UpdateSocialCredential(ci.ClientId, SocialConnector.Twitter, "oauthverifier", oauth_verifier);

                _clientInfo.TwitterId = me.ScreenName;

                db.RegisterClientInfo(
                    _clientInfo.LastName,
                    _clientInfo.FirstName,
                    _clientInfo.AddressLine1,
                    _clientInfo.AddressLine2,
                    _clientInfo.ZipCode,
                    _clientInfo.State,
                    _clientInfo.City,
                    _clientInfo.Country,
                    _clientInfo.Language,
                    _clientInfo.Telephone,
                    _clientInfo.Cellular,
                    _clientInfo.CompanyName,
                    _clientInfo.UserId,
                    _clientInfo.AccountOwner,
                    _clientInfo.BumaCode,
                    _clientInfo.SenaCode,
                    _clientInfo.IsrcCode,
                    _clientInfo.TwitterId,
                    _clientInfo.FacebookId,
                    _clientInfo.SoundCloudId,
                    _clientInfo.SoniallId,
                    _clientInfo.OwnerKind,
                    _clientInfo.CreditCardNr,
                    _clientInfo.CreditCardCvv,
                    _clientInfo.EmailReceipt,
                    _clientInfo.Referer,
                    _clientInfo.Gender,
                    _clientInfo.Birthdate,
                    _clientInfo.stagename);
            }
        }
Example #7
0
		private void button1_Click(object sender, EventArgs e)
		{
			string uris = "Couldn't connect to Server.Please retry again.";
			try
			{
				oatr = OAuthUtility.GetRequestToken(ConsumerKey, ConsumerSecret, "oob");
				Uri uri = Twitterizer.OAuthUtility.BuildAuthorizationUri(oatr.Token);
				uris = uri.ToString();
				webBrowser1.Navigate(uris);
			}
			catch
			{
				Interaction.InputBox("Couldn't open WebBrouser. Please copy this url and paste it to your brouser's URL box.", "Error", uris);
			}
		}
        private void _autorize()
        {
            OAuthTokenResponse tokenResponse = new OAuthTokenResponse();
            //tokenResponse = Twitterizer.OAuthUtility.GetRequestToken(consumerKey, consumerSecret, callbackAddy);
            tokenResponse = Twitterizer.OAuthUtility.GetRequestToken(m_config.AppConsumerKey, m_config.AppConsumerSecret, "oob");
            string pin = "";

            if (true)
            {
                // Need to check if the user is a valid user.

                //OAuthTokenResponse tokenResponse = new OAuthTokenResponse();
                //tokenResponse = Twitterizer.OAuthUtility.GetRequestToken(m_config.AppConsumerKey, m_config.AppConsumerSecret, "oob");
                //txt_login.Text = "Token is:  " + tokenResponse.Token.ToString();

                string target = "http://twitter.com/oauth/authorize?oauth_token=" + tokenResponse.Token;
                try
                {
                    System.Diagnostics.Process.Start(target);
                }
                catch (System.ComponentModel.Win32Exception noBrowser)
                {
                    if (noBrowser.ErrorCode == -2147467259)
                        MessageBox.Show(noBrowser.Message);
                }
                catch (System.Exception other)
                {
                    MessageBox.Show(other.Message);
                }

                pin = "3470994"; //This WILL NOT WORK. User needs to enter the PIN
                EnterPin enterpin = new EnterPin();
                enterpin.ShowDialog(); //show dialog causes it to wait for user input. Show() would not work
                //pin = Properties.Settings.Default.pin;
            }
            else
            {
                //pin = Properties.Settings.Default.pinSaved;
            }


            tokenResponse2 = OAuthUtility.GetAccessToken(m_config.AppConsumerKey, m_config.AppConsumerSecret, tokenResponse.Token, pin);
            m_config.Autorized = true;
            //txt_login.Text = "App " + tokenResponse2.ScreenName.ToString() + " access allowed.";
            
        }
Example #9
0
        private void authButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(keyTextBox.Text) || string.IsNullOrWhiteSpace(secretTextBox.Text))
            {
                MessageBox.Show("Please input consumer key & secret", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            res = OAuthUtility.GetRequestToken(keyTextBox.Text, secretTextBox.Text, "oob");
            Uri uri = OAuthUtility.BuildAuthorizationUri(res.Token);
            webBrowser.Navigate(uri);
            keyTextBox.Enabled = false;
            secretTextBox.Enabled = false;
            authButton.Enabled = false;
            pinTextBox.Enabled = true;
            okButton.Enabled = true;
        }
Example #10
0
        private void btn_PinCheck_Click(object sender, EventArgs e)
        {
            try
            {
                pin_check_response = OAuthUtility.GetAccessToken(OAuthData.ConsumerKey, OAuthData.ConsumerSecret, oauth_response.Token, txtBox_PinCheck.Text);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.DialogResult = DialogResult.Abort;
            }

            OAuthData.AccessToken = pin_check_response.Token;
            OAuthData.AccessTokenSecret = pin_check_response.TokenSecret;
            OAuthData.ScreenName = pin_check_response.ScreenName;

            this.DialogResult = DialogResult.OK;
        }
Example #11
0
 private void Login()
 {
     try
     {
         oauth_response = OAuthUtility.GetRequestToken(OAuthData.ConsumerKey, OAuthData.ConsumerSecret, OAuthData.CallBackAddress);
         webBrowser_Login.Navigate(new Uri(TwitterUri.OAuthAuthenticate + oauth_response.Token));
     }
     catch(Win32Exception noBrowser)
     {
         if(noBrowser.ErrorCode == -2147467259)
         {
             MessageBox.Show(noBrowser.Message);
             this.DialogResult = DialogResult.Abort;
         }
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message);
         this.DialogResult = DialogResult.Abort;
     }
 }
Example #12
0
 internal void CancelAuthorization()
 {
     currentRequestToken = null;
 }
Example #13
0
 public Uri autorizar()
 {
     tk = OAuthUtility.GetRequestToken(ConsumerKey, ConsumerSecret, "oob");
     return OAuthUtility.BuildAuthorizationUri(tk.Token);
 }
Example #14
0
        /// <summary>
        /// Gets the access token.
        /// </summary>
        /// <param name="consumerKey">The consumer key.</param>
        /// <param name="consumerSecret">The consumer secret.</param>
        /// <param name="requestToken">The request token.</param>
        /// <param name="verifier">The pin number or verifier string.</param>
        /// <returns>
        /// An <see cref="OAuthTokenResponse"/> class containing access token information.
        /// </returns>
        public static OAuthTokenResponse GetAccessToken(string consumerKey, string consumerSecret, string requestToken, string verifier)
        {
            if (string.IsNullOrEmpty(consumerKey))
            {
                throw new ArgumentNullException("consumerKey");
            }

            if (string.IsNullOrEmpty(consumerSecret))
            {
                throw new ArgumentNullException("consumerSecret");
            }

            if (string.IsNullOrEmpty(requestToken))
            {
                throw new ArgumentNullException("requestToken");
            }

            WebRequestBuilder builder = new WebRequestBuilder(
                new Uri("https://api.twitter.com/oauth/access_token"),
                HTTPVerb.GET,
                new OAuthTokens { ConsumerKey = consumerKey, ConsumerSecret = consumerSecret });

            if (!string.IsNullOrEmpty(verifier))
            {
                builder.Parameters.Add("oauth_verifier", verifier);
            }

            builder.Parameters.Add("oauth_token", requestToken);

            string responseBody;

            try
            {
                HttpWebResponse webResponse = builder.ExecuteRequest();

                responseBody = new StreamReader(webResponse.GetResponseStream()).ReadToEnd();
            }
            catch (WebException wex)
            {
                throw new TwitterizerException(wex.Message, wex);
            }

            OAuthTokenResponse response = new OAuthTokenResponse();
            response.Token = Regex.Match(responseBody, @"oauth_token=([^&]+)").Groups[1].Value;
            response.TokenSecret = Regex.Match(responseBody, @"oauth_token_secret=([^&]+)").Groups[1].Value;
            response.UserId = long.Parse(Regex.Match(responseBody, @"user_id=([^&]+)").Groups[1].Value, CultureInfo.CurrentCulture);
            response.ScreenName = Regex.Match(responseBody, @"screen_name=([^&]+)").Groups[1].Value;
            return response;
        }
Example #15
0
 public bool Update(OAuthTokenResponse token, string verifier)
 {
     try {
         var accessToken = GetAccessToken(token, verifier);
         AccessToken       = accessToken.Token;
         AccessTokenSecret = accessToken.TokenSecret;
         ScreenName        = accessToken.ScreenName;
         UserId            = accessToken.UserId;
     } catch {
         return false;
     }
     return true;
 }
Example #16
0
 public void AuthenticateTwitter()
 {
     GetOAuthForm f = new GetOAuthForm(CONSUMER_KEY, CONSUMER_SECRET);
     f.ShowDialog();
     if (f.OAuthTokenResponse != null)
     {
         AccessToken = f.OAuthTokenResponse.Token;
         AccessTokenSecret = f.OAuthTokenResponse.TokenSecret;
         UserDetails = f.OAuthTokenResponse;
     }
     else
     {
         System.Windows.Application.Current.Shutdown();
     }
 }
Example #17
0
        private void button4_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            Settings1.Default.pin = pinText.Text;
            Settings1.Default.Save();
            mytoken = OAuthUtility.GetAccessToken(Settings1.Default.consumerKey, Settings1.Default.consumerSecret, mytoken.Token, Settings1.Default.pin);

            authToken.ConsumerKey = Settings1.Default.consumerKey;
            authToken.ConsumerSecret = Settings1.Default.consumerSecret;
            authToken.AccessToken = mytoken.Token;
            authToken.AccessTokenSecret = mytoken.TokenSecret;

            TwitterUser myuser = new TwitterUser(authToken);
            TwitterStatusCollection mycollection = TwitterUser.GetTimeline(authToken);

            Settings1.Default.consumerKey = authToken.ConsumerKey;
            Settings1.Default.consumerSecret = authToken.ConsumerSecret;
            Settings1.Default.token = authToken.AccessToken;
            Settings1.Default.secretToken = authToken.AccessTokenSecret;

            Settings1.Default.Save();
            pinText.Text = Settings1.Default.pin;
            pinText.ReadOnly = true;
            authenticationButton.Enabled = false;
            authStatus.Text = "Authentication Successful!";
        }
Example #18
0
 public TwitterAccount(string accountName, string accessTokenString, string verficationString)
 {
     AccountName = accountName;
     AccessToken = (OAuthTokenResponse)SerializationHelper.Deserialize(typeof(OAuthTokenResponse), accessTokenString);
     VerificationString = verficationString;
 }
 private static string GetRequestUrl(OAuthTokenResponse token)
 {
     return string.Format("http://twitter.com/oauth/authorize?oauth_token={0}", token.Token);
 }
 public bool Authorize(string pin)
 {
     accessToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, requestToken, pin);
     return !string.IsNullOrEmpty(accessToken.Token);
 }
Example #21
0
        /// <summary>
        /// TWITTER AUTHENTICATION
        /// </summary>
        private void btnTwitterAuth_Click(object sender, EventArgs e)
        {
            oa_TokenResponse = OAuthUtility.GetRequestToken(
                settings.tw_cKey,
                settings.tw_cSec, "oob");

            tw = new WebBrowser();
            tw.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(tw_DocumentCompleted);
            tw.Navigate(OAuthUtility.BuildAuthorizationUri(oa_TokenResponse.Token, true));
        }
Example #22
0
 public TwitterAccount(string accountName, OAuthTokenResponse accessToken, string verificationString)
 {
     AccountName = accountName;
     AccessToken = accessToken;
     VerificationString = verificationString;
 }
Example #23
0
        internal void FinishAuthorization(string pin, out string AccessToken, out string AccessTokenSecret)
        {
            OAuthTokenResponse response = OAuthUtility.GetAccessToken(TwitterAccountConstants.oAuthConsumerKey, TwitterAccountConstants.oAuthConsumerSecret, currentRequestToken.Token, pin);

            AccessToken = response.Token;
            AccessTokenSecret = response.TokenSecret;

            tokens.AccessToken = AccessToken;
            tokens.AccessTokenSecret = AccessTokenSecret;

            currentRequestToken = null;
        }
Example #24
0
 public void UpdateTwitterAccount(OAuthTokenResponse atoken, TwUser usr)
 {
     usr.TokenSecret = atoken.TokenSecret;
         usr.Token = atoken.Token;
         db.SaveChanges();
 }
Example #25
0
 internal void StartNewAuthorization()
 {
     currentRequestToken = OAuthUtility.GetRequestToken(TwitterAccountConstants.oAuthConsumerKey, TwitterAccountConstants.oAuthConsumerSecret, "oob");
 }
Example #26
0
 public static string DirectUserToGetAuthKey(OAuthTokenResponse RequestToken)
 {
     return Twitter_AuthorizeURL + RequestToken.Token;
 }
Example #27
0
 private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     mytoken = OAuthUtility.GetRequestToken(Settings1.Default.consumerKey,Settings1.Default.consumerSecret);
     System.Diagnostics.Process.Start("http://twitter.com/oauth/authorize?oauth_token=" + mytoken.Token);
 }
Example #28
0
 public OAuthTokenResponse GetAccessToken(OAuthTokenResponse authorizationToken, string verifier)
 {
     return OAuthUtility.GetAccessToken(ConsumerKey, ConsumerSecret, authorizationToken.Token, verifier);
 }
Example #29
0
 public string GetAuthorizationUrl()
 {
     requestToken = OAuthUtility.GetRequestToken(consumerToken.Key, consumerToken.Secret, "oob");
     var authorizationUri = OAuthUtility.BuildAuthorizationUri(requestToken.Token);
     return authorizationUri.AbsoluteUri;
 }
Example #30
0
 private void GetRequestToken()
 {
     this.requestTokenResponse = OAuthUtility.GetRequestToken(consumerKey, consumerSecret, "oob");
 }