title: node js express twitter api login
body: <p>im a newbie with nodejs, actually i need to do a twitter login with the twitter API, i have been using this example <a href="http://moonlitscript.com/post.cfm/how-to-use-oauth-and-twitter-in-your-node-js-expressjs-app/" rel="nofollow">http://moonlitscript.com/post.cfm/how-to-use-oauth-and-twitter-in-your-node-js-expressjs-app/</a> so, after spending some time trying to understand jade and all these new little things for me, i have managed to write something, however i have no idea of how i should send the info on my login page to the method that handles the twitter login process. Is there someone who can help me to point in the right direction with this? thanks in advance.</p>
  
  <p>here's my code</p>
  
  <p>app.js</p>
  
  <pre><code>var express = require('express')
    , routes = require('./routes')
    , user = require('./routes/user')
    , http = require('http')
    , path = require('path')
    , OAuth= require('oauth').OAuth;
  
  var app = express();
  
  var oa = new OAuth(
  "https://api.twitter.com/oauth/request_token",
  "https://api.twitter.com/oauth/access_token",
  "occcccccccc",
  "fccccccccccccccccccccccccc",
  "1.0",
  "http://ccccccccccccc.c9.io/",
  "HMAC-SHA1"
  );
  
   app.get('/auth/twitter', function(req, res){
      oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){
      if (error) {
          console.log(error);
          res.send("yeah no. didn't work.")
      }
      else {
          req.session.oauth = {};
          req.session.oauth.token = oauth_token;
          console.log('oauth.token: ' + req.session.oauth.token);
          req.session.oauth.token_secret = oauth_token_secret;
          console.log('oauth.token_secret: ' +    req.session.oauth.token_secret);
          res.redirect('https://twitter.com/oauth/authenticate? oauth_token='+oauth_token)
  }
  });
  });
  
  app.get('/auth/twitter/callback', function(req, res, next){
  if (req.session.oauth) {
      req.session.oauth.verifier = req.query.oauth_verifier;
      var oauth = req.session.oauth;
  
      oa.getOAuthAccessToken(oauth.token,oauth.token_secret,oauth.verifier, 
      function(error, oauth_access_token, oauth_access_token_secret, results){
          if (error){
              console.log(error);
              res.send("yeah something broke.");
          } else {
              req.session.oauth.access_token = oauth_access_token;
              req.session.oauth,access_token_secret =      oauth_access_token_secret;
              console.log(results);
              res.send("worked. nice one.");
          }
      }
      );
  } else
      next(new Error("you're not supposed to be here."))
  });
  
  
  
  app.configure(function(){
    app.set('port', process.env.PORT || 3000);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.use(express.favicon());
    app.use(express.logger('dev'));
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);
    app.use(express.static(path.join(__dirname, 'public')));
  });
  
  app.get('/', function(req, res){
      res.render('index');
  });
  
  app.post('/', function(req,res){
    console.log(req.body);
  })
  
  app.configure('development', function(){
    app.use(express.errorHandler());
  });
  
  app.get('/', routes.index);
  
  //http.createServer(app).listen(app.get('port'), function(){
   //  console.log("Express server listening on port " + app.get('port'));
   //});
  
  app.listen(process.env.PORT, process.env.IP, function() {
    console.log("Listening on " + app.get('port'));
  });
  </code></pre>
  
  <p>index.jade</p>
  
  <pre><code>   form(name="input", action="/auth/twitter", method="get")
    |Username:
    input(type="text", name="user")
    |Password:
    input(type="password", name="pswd")
    input(type="submit", value="Submit")
  </code></pre>