async void OAuthForm_Load(object sender, EventArgs e) { pinAuth = new PinAuthorizer { // Get the ConsumerKey and ConsumerSecret for your app and load them here. CredentialStore = new InMemoryCredentialStore { ConsumerKey = ConfigurationManager.AppSettings["consumerKey"], ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"] }, // Note: GetPin isn't used here because we've broken the authorization // process into two parts: begin and complete GoToTwitterAuthorization = pageLink => OAuthWebBrowser.Navigate(new Uri(pageLink, UriKind.Absolute)) }; await pinAuth.BeginAuthorizeAsync(); }
async void Page_Loaded(object sender, RoutedEventArgs e) { pinAuth = new PinAuthorizer { // Get the ConsumerKey and ConsumerSecret for your app and load them here. CredentialStore = new InMemoryCredentialStore { ConsumerKey = "", ConsumerSecret = "" }, // Note: GetPin isn't used here because we've broken the authorization // process into two parts: begin and complete GoToTwitterAuthorization = pageLink => Dispatcher.BeginInvoke( () => OAuthWebBrowser.Navigate(new Uri(pageLink, UriKind.Absolute))) }; await pinAuth.BeginAuthorizeAsync(); }
private async Task OpenAuthorizationPageAsync() { _authorizer = new PinAuthorizer { CredentialStore = new InMemoryCredentialStore { ConsumerKey = ConsumerKey, ConsumerSecret = ConsumerSecret }, GoToTwitterAuthorization = pageLink => Process.Start(pageLink) }; try { await _authorizer.BeginAuthorizeAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
IAuthorizer PerformAuthorization() { // validate that credentials are present if (string.IsNullOrWhiteSpace(twitterConsumerKey) || string.IsNullOrWhiteSpace(twitterConsumerSecret)) { MessageBox.Show(@"Error while setting " + "App.config/appSettings. \n\n" + "You need to provide your twitterConsumerKey and twitterConsumerSecret in App.config \n" + "Please visit http://dev.twitter.com/apps for more info.\n"); return(null); } // configure the OAuth object var auth = new PinAuthorizer { CredentialStore = new InMemoryCredentialStore { ConsumerKey = twitterConsumerKey, ConsumerSecret = twitterConsumerSecret }, GoToTwitterAuthorization = pageLink => Process.Start(pageLink), GetPin = () => { // ugly hack string pin = ""; Dispatcher.Invoke((Action) (() => { PinWindow pinw = new PinWindow(); pinw.Owner = this; if (pinw.ShowDialog() == true) { pin = pinw.Pin; } else { pin = ""; } } )); return(pin); } }; return(auth); // start the authorization process (launches Twitter authorization page). try { Task t = auth.BeginAuthorizeAsync(); t.Wait(); } catch (WebException ex) { MessageBox.Show(ex.Message + "\n\nPlease make sure that:" + "\n\t- your computer's date/time is accurate;" + "\n\t- you entered the exact PIN returned by Twitter.", "Twitter Archive Eraser"); return(null); } return(auth); }