public OAuthDialog()
        {
            InitializeComponent();

            pinTextBox.Visibility = Visibility.Hidden;
            pinLbl.Visibility = Visibility.Hidden;
            pinInstruction.Visibility = Visibility.Hidden;

            _consumerKey = Settings.Default.ConsumerKey;
            _consumerSecret = Settings.Default.ConsumerSecret;

            //get a request token.  this is only used during
            //this process.
            IFluentTwitter getRequestTokenRequest = FluentTwitter.CreateRequest()
                .Authentication.GetRequestToken(_consumerKey, _consumerSecret);

            TwitterResult response = getRequestTokenRequest.Request();
            _requestToken = response.AsToken();

            //TODO: handle the case where the token is NULL because
            //twitter is down or broken in a manner suitable to your app

            //wait for the user to click the "Authorize button"
        }
 private static string SerializeToken(OAuthToken result)
 {
     return new JavaScriptSerializer().Serialize(result);
 }
Exemple #3
0
 public UserService(OAuthToken currentUserToken) : base(currentUserToken)
 {
 }
Exemple #4
0
 public SearchService(OAuthToken currentUserToken) : base(currentUserToken)
 {
 }
 public StatusesService(OAuthToken currentUserToken) : base(currentUserToken)
 {
 }
        public User Login(OAuthToken token)
        {
            var user = new User();
            // check that the stored authentication is valid
            ITwitterAccountVerifyCredentials twitter = CreateRequest().Account().VerifyCredentials();
            try
            {
                TwitterResult response = twitter.Request();
                if (response.IsTwitterError || response.IsNetworkError || response.IsFailWhale)
                {
                    return user;
                }

                var bogus = new Regex("\"user\"\\:\\{\"id\"\\:\\d+\\}\\,");
                response.Response = bogus.Replace(response.Response, string.Empty);

                TwitterUser retval = response.AsUser();
                if (retval != null) user = CreateUser(retval);
            }
            finally
            {
                CurrentlyLoggedInUser = user;
                _userRepo.Add(user);
            }
            return user;
        }
        public void FetchPin()
        {
            // get an authenticated request token from twitter
            _requestToken = GetRequestToken();
            if (_requestToken == null) return;

            // automatically starts the default web browser, sending the
            // user to the authorization URL.
            FluentTwitter.CreateRequest()
                .Authentication
                .AuthorizeDesktop(Properties.Settings.Default.ProStudioTweetConsumerKey,
                                  Properties.Settings.Default.ProStudioTweetConsumerSecret, _requestToken.Token);
        }
 private void UpdatePostLoginInterface(OAuthToken token)
 {
     TwitterClient.Login(token);
     if (TwitterClient.CurrentlyLoggedInUser != null)
     {
         var settings = new Settings
                            {
                                ScreenName = token.ScreenName,
                                Token = token.Token,
                                TokenSecret = token.TokenSecret,
                                LastUpdated = string.Empty
                            };
         SettingsService.SaveSettings(settings);
         RaiseEvent(new RoutedEventArgs(LoginEvent));
         Messenger.Default.Send(new RefreshTimelineMessage());
     }
     else
     {
         MessageBox.Show("Incorrect username or password. Please try again");
     }
 }
Exemple #9
0
 static void SaveAccessToken(OAuthToken accessToken)
 {
     Settings.Default.ScreenName = accessToken.ScreenName;
     Settings.Default.UserId = accessToken.UserId;
     Settings.Default.Token = accessToken.Token;
     Settings.Default.TokenSecret = accessToken.TokenSecret;
     Settings.Default.Save();
 }
Exemple #10
0
        static void Main(string[] args)
        {
            var requestToken = GetRequestToken(consumerKey, consumerSecret);
            token = requestToken.Token;
            tokenSecret = requestToken.TokenSecret;

            foreach (string arg in args)
            {
                if (string.Compare(arg, "auto", true) == 0)
                {
                    if (!string.IsNullOrWhiteSpace(screenName))
                    {
                        userAuth = GetAccessToken(screenName);
                        AutoTweet();
                    }

                    return;
                }
            }

            wl("{0} - {1} by {2}", PROGRAM_NAME, PROGRAM_DESC, AUTHOR);

            if (string.IsNullOrWhiteSpace(screenName))
            {
                bl();
                wl("This seems to be the first time you are using {0}.", PROGRAM_NAME);
                wl("First, you'll need to authorize {0} to access your Twitter account.", PROGRAM_NAME);
                bl();
                w("Press enter key to launch your default browser and the authentication process...");
                string input = rl();

                if (string.Compare(input, "exit", true) == 0)
                    return;

                FluentTwitter.CreateRequest().Authentication.AuthorizeDesktop(consumerKey, consumerSecret, token);

                w("Enter the PIN provided by twitter.com: ");
                string pin = rl();

                var access = GetAccessToken(consumerKey, consumerSecret, token, pin);
                screenName = access.ScreenName;
                SaveAccessToken(access);
            }

            userAuth = GetAccessToken(screenName);

            DisplayMenu();

            w("Press any key to exit...");
            Console.ReadKey();
        }
Exemple #11
0
        static OAuthToken GetAccessToken(string screenName)
        {
            OAuthToken oAuth = new OAuthToken();
            oAuth.ScreenName = screenName;
            oAuth.UserId = Settings.Default.UserId;
            oAuth.Token = Settings.Default.Token;
            oAuth.TokenSecret = Settings.Default.TokenSecret;

            return oAuth;
        }