Пример #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());
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var url =
                CredentialsCreator.GetAuthorizationURL(TwitterConnectionInfoSingleton.getInstance().GetAppCredentials());

            TwitterPin.Source = new Uri(url);
        }
Пример #3
0
        public static void GetTwitterAuthorizationUrl()
        {
            _applicationCredentials = new TwitterCredentials(ConfigurationManager.AppSettings["twitterConsumerKey"],
                                                             ConfigurationManager.AppSettings["twitterConsumerSecret"]);
            var url = CredentialsCreator.GetAuthorizationURL(_applicationCredentials);

            System.Diagnostics.Process.Start(url);
        }
Пример #4
0
        public ActionResult TwitterAuth()
        {
            var appCreds    = new ConsumerCredentials(CONSUMER_KEY, CONSUMER_SECRET);
            var redirectURL = "http://" + Request.Url.Authority + "/Home/ValidateTwitterAuth";
            var url         = CredentialsCreator.GetAuthorizationURL(appCreds, redirectURL);

            return(new RedirectResult(url));
        }
Пример #5
0
 private void Window_btnAuthorizeClicked(object sender, EventArgs e)
 {
     try
     {
         // Make the user go on the URL so that Twitter authenticates him and gives a PIN code
         Process.Start(CredentialsCreator.GetAuthorizationURL(AppCredentials));
     }
     catch (Exception)
     {
         new ErrorDialog("Cannot connect with server");
         Window.Close();
     }
 }
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState)
        {
            NavigationService.ClearHistory();

            AppCredentials = new TwitterCredentials(TweetinviData.ConsumerKey, TweetinviData.ConsumerSecret);
            var url = CredentialsCreator.GetAuthorizationURL(AppCredentials);

            if (String.IsNullOrEmpty(url))
            {
                NavigationService.Navigate(typeof(Views.MainPage));
            }

            Uri targeturi = new Uri(url);

            NavigationService.Navigate(typeof(Views.LoginPage), targeturi);

            await Task.CompletedTask;
        }
Пример #7
0
        private void GetCredentials()
        {
            // Check for saved credentials JSON file
            string fileName = "credentials.json";

            if (File.Exists(fileName))
            {
                try
                {
                    Console.WriteLine("Retrieving saved credentials...");
                    StreamReader reader = new StreamReader(fileName);
                    string       json   = reader.ReadToEnd();
                    reader.Close();
                    AuthInfo = JsonConvert.DeserializeObject <AuthInfo>(json);
                }
                catch (Exception)
                {
                    Console.WriteLine("Error deserializing credentials.");
                }
            }
            else
            {
                var    credentials = CredentialsCreator.GenerateApplicationCredentials(Keys.API_KEY, Keys.API_SECRET);
                string url         = CredentialsCreator.GetAuthorizationURL(credentials);
                System.Diagnostics.Process.Start(url); // Open web browser

                Console.WriteLine("Enter PIN:");
                string pin           = Console.ReadLine();
                var    authorization = CredentialsCreator.GetCredentialsFromVerifierCode(pin, credentials);
                AuthInfo = new AuthInfo(Keys.API_KEY, Keys.API_SECRET, authorization.AccessToken, authorization.AccessTokenSecret);

                Console.WriteLine("Would you like to save these credentials so that you don't have to authenticate next time?\nY/N");
                var reply = Console.ReadKey();
                if (reply.Key.ToString() == "Y")
                {
                    string       json   = JsonConvert.SerializeObject(AuthInfo);
                    StreamWriter writer = new StreamWriter(fileName);
                    writer.WriteLine(json);
                    writer.Close();
                }
            }
        }
Пример #8
0
        /*
         * Function that handles the first program load
         */
        private static void showDialog()
        {
            var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(Properties.Resources.api_key,
                                                                                           Properties.Resources.api_key_secret);
            var     url  = CredentialsCreator.GetAuthorizationURL(applicationCredentials);
            PinForm form = new PinForm(url);

            Application.Run(form);
            captcha = form.getCap();
            try
            {
                var newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(captcha, applicationCredentials);
                Properties.Settings.Default.access_token        = newCredentials.AccessToken;
                Properties.Settings.Default.access_token_secret = newCredentials.AccessTokenSecret;
                Properties.Settings.Default.Save();
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
                Application.Exit();
            }
        }
Пример #9
0
        /// <summary>
        /// Requests an authentication token and redirects the user to Twitter
        /// </summary>
        public ActionResult Oauth()
        {
            ConsumerCredentials appCreds;

            string redirectURL, oauthURL;

            try
            {
                Session[SK.Redirect] = Request.QueryString["redirect_uri"];

                appCreds = new ConsumerCredentials(consumerKey, consumerSecret);

                redirectURL = "http://" + Request.Url.Authority + "/twitter/callback";

                oauthURL = CredentialsCreator.GetAuthorizationURL(appCreds, redirectURL);

                return(new RedirectResult(oauthURL));
            }
            catch (Exception)
            {
                return(new RedirectResult("/twitter/check"));
            }
        }