private void CreateNewRequestToken() { var service = new TwitterService(ClientInfo); UnauthorizedToken = service.GetRequestToken(); AuthenticationUrl = service.GetAuthorizationUri(UnauthorizedToken); }
public Uri GetAutheticationUri(IDictionary <string, string> parameters, Uri callback) { var callbackUri = new UriBuilder(callback) { Query = string.Format("context={0}", parameters["wctx"]) }; // Pass your credentials to the service string consumerKey = _settings.TwitterConsumerKey; string consumerSecret = _settings.TwitterConsumerSecret; var service = new TwitterService(consumerKey, consumerSecret); // Retrieve an OAuth Request Token string returnUri = callbackUri.ToString(); OAuthRequestToken requestToken; try { requestToken = service.GetRequestToken(returnUri); } catch (ArgumentException e) { string message = string.Format("Failed to request twitter auth token, code: {0}, exception: {1}", service.Response.StatusCode, service.Response.InnerException); throw new ArgumentException(message, e); } // Redirect to the OAuth Authorization URL return(service.GetAuthorizationUri(requestToken)); }
public Uri GetRequestURI() { OAuthRequestToken requestToken = twitter.GetRequestToken(callbackURL); Uri uri = twitter.GetAuthorizationUri(requestToken); return(uri); }
public void Can_make_protected_resource_request_with_access_token() { var service = new TwitterService(_consumerKey, _consumerSecret); var request = service.GetRequestToken(); AssertResultWas(service, HttpStatusCode.OK); Assert.NotNull(request); var uri = service.GetAuthorizationUri(request); Process.Start(uri.ToString()); Console.WriteLine("Press the any key when you have confirmation of your code transmission."); var verifier = "1234567"; // <-- Debugger breakpoint and edit with the actual verifier var access = service.GetAccessToken(request, verifier); AssertResultWas(service, HttpStatusCode.OK); Assert.IsNotNull(access); service.AuthenticateWith(access.Token, access.TokenSecret); var mentions = service.ListTweetsMentioningMe(new ListTweetsMentioningMeOptions()); Assert.IsNotNull(mentions); Assert.AreEqual(20, mentions.Count()); }
public void Login(String username, String password) { Uri uri = service.GetAuthorizationUri(requestToken); CookieContainer cookieContainer = new CookieContainer(); String response = HttpUtil.GetResponseString(uri, cookieContainer); int startIndex = response.IndexOf("authenticity_token\" type=\"hidden\" value=\"") + 41; int endIndex = response.IndexOf("\"", startIndex + 1); String authenticity_token = response.Substring(startIndex, endIndex - startIndex); startIndex = response.IndexOf("name=\"oauth_token\" type=\"hidden\" value=\"") + 40; endIndex = response.IndexOf("\"", startIndex + 1); String oauth_token = response.Substring(startIndex, endIndex - startIndex); String postData = "authenticity_token=" + authenticity_token + "&oauth_token=" + oauth_token + "&session%5Busername_or_email%5D=" + username + "&session%5Bpassword%5D=" + password; response = HttpUtil.GetResponseString(new Uri("https://api.twitter.com/oauth/authorize"), postData, cookieContainer); if (response.Contains("Invalid user name or password")) { return; } startIndex = response.IndexOf("<code>") + 6; endIndex = response.IndexOf("</code>"); String pin = response.Substring(startIndex, endIndex - startIndex); OAuthAccessToken access = service.GetAccessToken(requestToken, pin); service.AuthenticateWith(access.Token, access.TokenSecret); }
/// <summary> /// Begin login process. /// </summary> private void btnLogin_Click(object sender, RoutedEventArgs e) { // Try to see if the user has already logged in try { // Look for the file containing previous tokens XmlDocument doc = new XmlDocument(); doc.Load(ConfigurationManager.AppSettings["LoginDataFile"]); XmlNode root = doc.LastChild; string token = root.FirstChild.InnerText; string tokenSecret = root.LastChild.InnerText; service.AuthenticateWith(token, tokenSecret); MoveToMain(); } // Login file not found so begin online authorization via browser. // Login process continues by inputing the pin recived later. catch (FileNotFoundException ex) { // Step 1 - Retrieve an OAuth Request Token requestToken = service.GetRequestToken(); // Step 2 - Redirect to the OAuth Authorization URL Uri uri = service.GetAuthorizationUri(requestToken); Process.Start(uri.ToString()); spPin.Visibility = Visibility.Visible; btnLogin.IsEnabled = false; } // Something went wrong catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Logs into Twitter, using OAuth. The user will need to copy/paste the Twitter auth code back into the console program. /// </summary> /// <returns>TwitterService</returns> private static TwitterService LoginTwitter() { // Pass your credentials to the service TwitterService service = new TwitterService(_consumerKey, _consumerSecret); // Step 1 - Retrieve an OAuth Request Token OAuthRequestToken requestToken = service.GetRequestToken(); // Step 2 - Redirect to the OAuth Authorization URL Uri uri = service.GetAuthorizationUri(requestToken); Process.Start(uri.ToString()); Console.Write("Enter Twitter auth key: "); string key = Console.ReadLine(); // Step 3 - Exchange the Request Token for an Access Token string verifier = key; // <-- This is input into your application by your user OAuthAccessToken access = service.GetAccessToken(requestToken, verifier); // Step 4 - User authenticates using the Access Token service.AuthenticateWith(access.Token, access.TokenSecret); return(service); }
public LoginProfile ProcessAuthoriztion(HttpContext context, IDictionary <string, string> @params) { var twitterService = new TwitterService(KeyStorage.Get("twitterKey"), KeyStorage.Get("twitterSecret")); if (String.IsNullOrEmpty(context.Request["oauth_token"]) || String.IsNullOrEmpty(context.Request["oauth_verifier"])) { var requestToken = twitterService.GetRequestToken(context.Request.Url.AbsoluteUri); var uri = twitterService.GetAuthorizationUri(requestToken); context.Response.Redirect(uri.ToString(), true); } else { var requestToken = new OAuthRequestToken { Token = context.Request["oauth_token"] }; var accessToken = twitterService.GetAccessToken(requestToken, context.Request["oauth_verifier"]); twitterService.AuthenticateWith(accessToken.Token, accessToken.TokenSecret); var user = twitterService.VerifyCredentials(new VerifyCredentialsOptions()); return(ProfileFromTwitter(user)); } return(new LoginProfile()); }
public string Authorize(string callbackUrl) { var requestToken = twitterService.GetRequestToken(callbackUrl); // <-- The registered callback URL var uri = twitterService.GetAuthorizationUri(requestToken); return(uri.ToString()); }
/// <summary> /// метод для авторизации пользователя /// </summary> public void Authorization() { OAuthRequestToken requestToken; Uri uri; try { twitterService = new TwitterService(consumerKey, consumerSecret); requestToken = twitterService.GetRequestToken(); if (requestToken == null) { MessageBox.Show("Не удалось выполнить запрос."); } uri = twitterService.GetAuthorizationUri(requestToken); Process.Start(uri.ToString()); string code = string.Empty; LoginViewModel loginViewModel = new LoginViewModel(code); var access = twitterService.GetAccessToken(requestToken, loginViewModel.Verifier); twitterService.AuthenticateWith(access.Token, access.TokenSecret); } catch (Exception ex) { MessageBox.Show(ex.Message, "Oopss", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public ActionResult Authorize() { TwitterService service = new TwitterService(_consumerKey, _consumerSecret); OAuthRequestToken requestToken = service.GetRequestToken(); var uri = service.GetAuthorizationUri(requestToken); return new RedirectResult(uri.ToString(), false /*permanent*/); }
/// <summary> /// WizardPage41_Load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WizardPage41_Load(object sender, EventArgs e) { requestToken = twitterService.GetRequestToken(); var uri = twitterService.GetAuthorizationUri(requestToken); webBrowser1.Navigate(uri.ToString()); }
/// <summary> /// FormAuthSocialLogin_Load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormAuthSocialLogin_Load(object sender, EventArgs e) { requestToken = service.GetRequestToken(); var uri = service.GetAuthorizationUri(requestToken); webBrowser1.Navigate(uri.ToString()); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); _twitterService = new TwitterService(Constants.ConsumerKey, Constants.ConsumerSecret); _requestToken = _twitterService.GetRequestToken(); _url = _twitterService.GetAuthorizationUri(_requestToken).ToString(); }
public ActionResult Login(string returnUrl) { var service = new TwitterService(ConsumerKey, ConsumerSecret); var requestToken = service.GetRequestToken(Url.Action("LoginCallback", "Auth", new { returnUrl }, Request.Url.Scheme)); var uri = service.GetAuthorizationUri(requestToken); return(Redirect(uri.ToString())); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); _twitterService = new TwitterService(Constants.ConsumerKey, Constants.ConsumerSecret); _requestToken = _twitterService.GetRequestToken(); //_applicationCredentials = CredentialsCreator.GenerateApplicationCredentials); _url = _twitterService.GetAuthorizationUri(_requestToken).ToString(); }
private void Request() { requestToken = service.GetRequestToken(); Uri uri = service.GetAuthorizationUri(requestToken); Process.Start(uri.ToString()); OnRequestEvent(); }
public ActionResult Authorize() { TwitterService service = new TwitterService(_consumerKey, _consumerSecret); OAuthRequestToken requestToken = service.GetRequestToken(); var uri = service.GetAuthorizationUri(requestToken); return(new RedirectResult(uri.ToString(), false /*permanent*/)); }
private void Authorize_Click(object sender, EventArgs e) { SetupTwitterClient(); requestToken = twitterService.GetRequestToken(); var authUrl = twitterService.GetAuthorizationUri(requestToken); Process.Start(authUrl.ToString()); }
public Settings() { InitializeComponent(); service = new TwitterService(SettingHelper.ConsumerKey, SettingHelper.ConsumerSecret); requestToken = service.GetRequestToken(); Uri uri = service.GetAuthorizationUri(requestToken); WebBrowser.Navigate(uri); }
public void getPIN() { // Step 1 - Retrieve an OAuth Request Token _requestToken = service.GetRequestToken(); // Step 2 - Redirect to the OAuth Authorization URL Uri uri = service.GetAuthorizationUri(_requestToken); Process.Start(uri.ToString()); }
public GetRequestTokenResponse GetRequestToken() { OAuthRequestToken requestToken = _twitterService.GetRequestToken(); Uri uri = _twitterService.GetAuthorizationUri(requestToken); return(new GetRequestTokenResponse { RequestToken = requestToken, AuthorizationUri = uri }); }
private void OpenAutorizePage() { const string consumerKey = "o4iyHtNojZ5Vrc9oqeRKLCPqJ"; const string consumerSecret = "SMbH4Y4ekOU6F08K4Y0cWAGs89BAzUfNcN7Za5BujYe2ula9MA"; service = new TwitterService(consumerKey, consumerSecret); requestToken = service.GetRequestToken(); var uri = service.GetAuthorizationUri(requestToken); browser.Navigate(uri); }
public ActionResult GetConnectedWithTwitter() { string _consumerKey = System.Configuration.ConfigurationManager.AppSettings["consumerKeyLogin"]; string _consumerSecret = System.Configuration.ConfigurationManager.AppSettings["consumerSecretLogin"]; TwitterService service = new TwitterService(_consumerKey, _consumerSecret); OAuthRequestToken requestToken = service.GetRequestToken(); var uri = service.GetAuthorizationUri(requestToken); return(new RedirectResult(uri.ToString(), false /*permanent*/)); }
public ActionResult Authorize() { // Step 1 - Retrieve an OAuth Request Token TwitterService service = new TwitterService(_consumerKey, _consumerSecret); // This is the registered callback URL OAuthRequestToken requestToken = service.GetRequestToken("https://localhost:51768/Twitter/AuthorizeCallback"); // Step 2 - Redirect to the OAuth Authorization URL Uri uri = service.GetAuthorizationUri(requestToken); return(new RedirectResult(uri.ToString(), false /*permanent*/)); }
private void OpenAuthorizePage() { const string consumerKey = "YGn1Aw1TcrTSXhP1RYrRt3ZnH"; const string consumerSecret = "Icn6kzlL07LhXJXwuJqk10k4hPDiMZzoKGlREvLjRyo7WtFL42"; twitterService = new TwitterService(consumerKey, consumerSecret); requestToken = twitterService.GetRequestToken(); var uri = twitterService.GetAuthorizationUri(requestToken); browser.Navigate(uri); }
protected virtual void HandleAuthenticationRequestToken(OAuthRequestToken token, TwitterResponse response) { _requestToken = token; // Save the token while (!_browserLoaded) { Thread.Sleep(200); } Dispatcher.BeginInvoke( () => _browser.Navigate(_service.GetAuthorizationUri(_requestToken)) ); }
public ActionResult Authorize() { // Step 1 - Retrieve an OAuth Request Token TwitterService service = new TwitterService("RP210WVfv1GbkYOd3oaHw", "z6p22FQTTU3ADIpjp6PThKyVWLAmikUfUfiOdycfm4w"); // This is the registered callback URL OAuthRequestToken requestToken = service.GetRequestToken("http://localhost:8081/Twitter/AuthorizeCallback"); // Step 2 - Redirect to the OAuth Authorization URL Uri uri = service.GetAuthorizationUri(requestToken); return(new RedirectResult(uri.ToString(), false /*permanent*/)); }
protected void btnSignInToTwitter_Click(object sender, EventArgs e) { // Step 1 - Retrieve an OAuth Request Token TwitterService service = new TwitterService(Global.TwitterConsumerKey, Global.TwitterConsumerSecret); // This is the registered callback URL OAuthRequestToken requestToken = service.GetRequestToken("http://" + Request.Url.Host + ":" + Request.Url.Port + "/api/TwAuthCallback.ashx"); // Step 2 - Redirect to the OAuth Authorization URL Uri uri = service.GetAuthorizationUri(requestToken); Response.Redirect(uri.ToString()); }
public ActionResult TwitterSignIn() { // Request an OAuth Request Token TwitterService twitterService = new TwitterService(OAuthAPIKey, OAuthAPISecret); //callback URL is locked to this application by the Twitter App itself OAuthRequestToken requestToken = twitterService.GetRequestToken(); // Redirect to the OAuth Authorization URL Uri uri = twitterService.GetAuthorizationUri(requestToken); return(new RedirectResult(uri.ToString(), false)); }
public AuthorizeLinkedIn() { TwitterClientInfo twitterClientInfo = new TwitterClientInfo(); twitterClientInfo.ConsumerKey = ConsumerKey; //Read ConsumerKey out of the app.config twitterClientInfo.ConsumerSecret = ConsumerSecret; //Read the ConsumerSecret out the app.config TwitterService twitterService = new TwitterService(twitterClientInfo); if (string.IsNullOrEmpty(AccessToken) || string.IsNullOrEmpty(AccessTokenSecret)) { //Now we need the Token and TokenSecret //Firstly we need the RequestToken and the AuthorisationUrl OAuthRequestToken requestToken = twitterService.GetRequestToken(); Uri authUrl = twitterService.GetAuthorizationUri(requestToken); //authUrl is just a URL we can open IE and paste it in if we want Console.WriteLine("Please Allow This App to send Tweets on your behalf"); Process.Start(authUrl.ToString()); //Launches a browser that'll go to the AuthUrl. //Allow the App Console.WriteLine("Enter the PIN from the Browser:"); string pin = Console.ReadLine(); OAuthAccessToken accessToken = twitterService.GetAccessToken(requestToken, pin); string token = accessToken.Token; //Attach the Debugger and put a break point here string tokenSecret = accessToken.TokenSecret; //And another Breakpoint here Console.WriteLine("Write Down The AccessToken: " + token); Console.WriteLine("Write Down the AccessTokenSecret: " + tokenSecret); } twitterService.AuthenticateWith(AccessToken, AccessTokenSecret); //twitterService.SendTweet("A Simple Tweet from a Simple Twitter Client"); //Console.WriteLine("Enter a Tweet"); //string tweetMessage; //while (true) //{ // tweetMessage = Console.ReadLine(); // if (tweetMessage.ToLower() == "exit") // { // break; // } // twitterService.SendTweet(tweetMessage); //} var x = twitterService.ListFollowerIdsOf("_glynster_", -1); }
public void Can_exchange_for_access_token() { var service = new TwitterService(_consumerKey, _consumerSecret); var requestToken = service.GetRequestToken(); AssertResultWas(service, HttpStatusCode.OK); Assert.NotNull(requestToken); var uri = service.GetAuthorizationUri(requestToken); Process.Start(uri.ToString()); Console.WriteLine("Press the any key when you have confirmation of your code transmission."); var verifier = "1234567"; // <-- Debugger breakpoint and edit with the actual verifier OAuthAccessToken accessToken = service.GetAccessToken(requestToken, verifier); AssertResultWas(service, HttpStatusCode.OK); Assert.IsNotNull(accessToken); }