index.js
function(req, res, next) {
    var requestTokenUrl = 'https://api.twitter.com/oauth/request_token';
    var accessTokenUrl = 'https://api.twitter.com/oauth/access_token';
    var authenticateUrl = 'https://api.twitter.com/oauth/authenticate';

    // Step 2. Redirect to the authorization screen.
    if (!req.query.oauth_token || !req.query.oauth_verifier) {
      var requestTokenOauth = {
        consumer_key: config.TWITTER_KEY,
        consumer_secret: config.TWITTER_SECRET,
        callback: config.TWITTER_CALLBACK
      };

      request.post({ url: requestTokenUrl, oauth: requestTokenOauth }, function(err, response, body) {
        var oauthToken = qs.parse(body);
        var params = qs.stringify({ oauth_token: oauthToken.oauth_token });

        res.redirect(authenticateUrl + '?' + params);
      });
      return;
    } 

    // Step 3. Exchange oauth token and oauth verifier for access token.
    var accessTokenOauth = {
      consumer_key: config.TWITTER_KEY,
      consumer_secret: config.TWITTER_SECRET,
      token: req.query.oauth_token,
      verifier: req.query.oauth_verifier
    };

    request.post({ url: accessTokenUrl, oauth: accessTokenOauth }, function(err, response, profile) {
      if (err) {
        res.status(500).send(err);
        return;
      } 
      req.profile = qs.parse(profile);
      next();
    });
  }
function(req, res, next) {
    var requestTokenUrl = 'https://api.twitter.com/oauth/request_token';
    var accessTokenUrl = 'https://api.twitter.com/oauth/access_token';
    var authenticateUrl = 'https://api.twitter.com/oauth/authenticate';

    // Step 2. Redirect to the authorization screen.
    if (!req.query.oauth_token || !req.query.oauth_verifier) {
      var requestTokenOauth = {
        consumer_key: config.TWITTER_KEY,
        consumer_secret: config.TWITTER_SECRET,
        callback: config.TWITTER_CALLBACK
      };

      request.post({ url: requestTokenUrl, oauth: requestTokenOauth }, function(err, response, body) {
        var oauthToken = qs.parse(body);
        var params = qs.stringify({ oauth_token: oauthToken.oauth_token });

        res.redirect(authenticateUrl + '?' + params);
      });
      return;
    } 

    // Step 3. Exchange oauth token and oauth verifier for access token.
    var accessTokenOauth = {
      consumer_key: config.TWITTER_KEY,
      consumer_secret: config.TWITTER_SECRET,
      token: req.query.oauth_token,
      verifier: req.query.oauth_verifier
    };

    request.post({ url: accessTokenUrl, oauth: accessTokenOauth }, function(err, response, profile) {
      if (err) {
        res.status(500).send(err);
        return;
      } 
      req.profile = qs.parse(profile);
      next();
    });
  }
function ( req , res , next ) { var requestTokenUrl = 'https://api.twitter.com/oauth/request_token' ; var accessTokenUrl = 'https://api.twitter.com/oauth/access_token' ; var authenticateUrl = 'https://api.twitter.com/oauth/authenticate' ; // Step 2. Redirect to the authorization screen. if ( ! req . query . oauth_token || ! req . query . oauth_verifier ) { var requestTokenOauth = { consumer_key : config . TWITTER_KEY , consumer_secret : config . TWITTER_SECRET , callback : config . TWITTER_CALLBACK } ; request . post ( { url : requestTokenUrl , oauth : requestTokenOauth } , function ( err , response , body ) { var oauthToken = qs . parse ( body ) ; var params = qs . stringify ( { oauth_token : oauthToken . oauth_token } ) ; res . redirect ( authenticateUrl + '?' + params ) ; } ) ; return ; } // Step 3. Exchange oauth token and oauth verifier for access token. var accessTokenOauth = { consumer_key : config . TWITTER_KEY , consumer_secret : config . TWITTER_SECRET , token : req . query . oauth_token , verifier : req . query . oauth_verifier } ; request . post ( { url : accessTokenUrl , oauth : accessTokenOauth } , function ( err , response , profile ) { if ( err ) { res . status ( 500 ) . send ( err ) ; return ; } req . profile = qs . parse ( profile ) ; next ( ) ; } ) ; }
Step 1. Obtain request token for the authorization popup.
Step 1 . Obtain request token for the authorization popup .