How to use passport-twitter - 10 common examples

To help you get started, we’ve selected a few passport-twitter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github robotastic / smartnet-player / index.js View on Github external
} else {
                    console.log("User not deserialized");
                    done(null, null);

                }
            });
    });


});

// Use the TwitterStrategy within Passport.
//   Strategies in passport require a `verify` function, which accept
//   credentials (in this case, a token, tokenSecret, and Twitter profile), and
//   invoke a callback with a user object.
twitterAuthn = new TwitterStrategy({
        consumerKey: config.twitterConsumerKey,
        consumerSecret: config.twitterConsumerSecret,
        callbackURL: "http://openmhz.com/auth/twitter/callback"
    },
    function (token, tokenSecret, profile, done) {
        // asynchronous verification, for effect...
        process.nextTick(function () {
            profile.token = token;
            profile.tokenSecret = tokenSecret;
            //console.log(profile);
            // To keep the example simple, the user's Twitter profile is returned to
            // represent the logged-in user.  In a typical application, you would want
            // to associate the Twitter account with a user record in your database,
            // and return that user instead.
            return done(null, profile);
        });
github gitana / cloudcms-server / middleware / authentication / providers / twitter.js View on Github external
constructor(req, config)
    {
        super(req, config);

        if (!config.properties) {
            config.properties = {};
        }
        if (!config.properties.id) {
            config.properties.id = "id";
        }

        // passport
        this.twitterStrategy = new TwitterStrategy({
            consumerKey: config.consumerKey,
            consumerSecret: config.consumerSecret,
            callbackURL: config.callbackURL,
            passReqToCallback: true
        }, auth.buildPassportCallback(config, provider));

        req.passport.use(this.twitterStrategy);
    }
github fossasia / loklak_walls / mongo / config / passport.js View on Github external
if (err)
                    throw err;

                  return done(null, newUser);
                });
              }

            });
});

}));

// =========================================================================
// TWITTER =================================================================
// =========================================================================
passport.use(new TwitterStrategy({

  consumerKey     : config.twitterConsumerKey,
  consumerSecret  : config.twitterConsumerSecret,
  callbackURL     : config.twitterCallbackUrl,
  passReqToCallback : true 
  },

  function(req, token, tokenSecret, profile, done) {

    process.nextTick(function() {

        if (!req.user) {

          User.findOne({ 'twitter.id' : profile.id }, function(err, user) {
            if (err)
              return done(err);
github weseek / growi / src / server / service / passport.js View on Github external
// check whether the strategy has already been set up
    if (this.isTwitterStrategySetup) {
      throw new Error('TwitterStrategy has already been set up');
    }

    const { configManager } = this.crowi;
    const isTwitterEnabled = configManager.getConfig('crowi', 'security:passport-twitter:isEnabled');

    // when disabled
    if (!isTwitterEnabled) {
      return;
    }

    debug('TwitterStrategy: setting up..');
    passport.use(
      new TwitterStrategy(
        {
          consumerKey: configManager.getConfig('crowi', 'security:passport-twitter:consumerKey'),
          consumerSecret: configManager.getConfig('crowi', 'security:passport-twitter:consumerSecret'),
          callbackURL: (this.crowi.appService.getSiteUrl() != null)
            ? urljoin(this.crowi.appService.getSiteUrl(), '/passport/twitter/callback') // auto-generated with v3.2.4 and above
            : configManager.getConfig('crowi', 'security:passport-twitter:callbackUrl'), // DEPRECATED: backward compatible with v3.2.3 and below
          skipUserProfile: false,
        },
        (accessToken, refreshToken, profile, done) => {
          if (profile) {
            return done(null, profile);
          }

          return done(null, false);
        },
      ),
github bilashcse / Online-Video-Editor / config / passport.js View on Github external
})
          }
        });
        
        
      }
      
    }
  ));

  //function


  // use twitter strategy
  passport.use(new TwitterStrategy({
        consumerKey: config.twitter.clientID
      , consumerSecret: config.twitter.clientSecret
      , callbackURL: config.twitter.callbackURL
      , passReqToCallback: true
    },
    function(req,token, tokenSecret, profile, done) {
      if(!req.user)
      {

        User.findOne({ 'twitter.id_str': profile.id }, function (err, user) {
          if (err) { return done(err) }
          if (!user) {
           
          user = new User({twitter: profile._json});
          user.name=user.twitter.screen_name;
          user.loginCount++;
github dexterlabora / excap-social / config / passport.js View on Github external
user.linkedin.profile = profile;

                user.save(function(err) {
                    if (err)
                        return done(err);

                    return done(null, user);
                });
            }
        });
    }));

    // =========================================================================
    // TWITTER =================================================================
    // =========================================================================
    passport.use(new TwitterStrategy({

        consumerKey     : configAuth.twitterAuth.consumerKey,
        consumerSecret  : configAuth.twitterAuth.consumerSecret,
        callbackURL     : configAuth.twitterAuth.callbackURL,
        passReqToCallback : true // allows us to pass in the req from our route (lets us check if a user is logged in or not)

    },
    function(req, token, tokenSecret, profile, done) {
        
        // asynchronous
        process.nextTick(function() {

            // check if the user is already logged in
            if (!req.user) {

                User.findOne({ 'twitter.id' : profile.id }, function(err, user) {
github mhaidarh / super-workshop-js / servers / server-express / auth / providers.js View on Github external
providers.github))

  // ---------------------------------------------------------------------------
  // FACEBOOK
  passport.use(new FacebookStrategy({
    clientID: process.env.FACEBOOK_APP_ID,
    clientSecret: process.env.FACEBOOK_APP_SECRET,
    callbackURL: process.env.FACEBOOK_CALLBACK,
    profileFields: process.env.FACEBOOK_SCOPE,
    passReqToCallback: true
  },
  providers.facebook))

  // ---------------------------------------------------------------------------
  // TWITTER
  passport.use(new TwitterStrategy({
    consumerKey: process.env.TWITTER_API_KEY,
    consumerSecret: process.env.TWITTER_API_SECRET,
    callbackURL: process.env.TWITTER_CALLBACK,
    passReqToCallback: true
  },
  providers.twitter))

  // ---------------------------------------------------------------------------
  // GOOGLE
  passport.use(new GoogleStrategy({
    clientID: process.env.GOOGLE_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    callbackURL: process.env.GOOGLE_CALLBACK,
    passReqToCallback: true
  },
  providers.google))
github kriasoft / app-starter-kit / api / src / passport.js View on Github external
`${profile.name.givenName} ${profile.name.familyName}`;
        const user = await login(req, 'facebook', profile, {
          accessToken,
          refreshToken,
        });
        done(null, user);
      } catch (err) {
        done(err);
      }
    },
  ),
);

// https://github.com/jaredhanson/passport-twitter
passport.use(
  new TwitterStrategy(
    {
      consumerKey: process.env.TWITTER_KEY,
      consumerSecret: process.env.TWITTER_SECRET,
      callbackURL: '/login/twitter/return',
      includeEmail: true,
      includeStatus: false,
      passReqToCallback: true,
    },
    async (req, token, tokenSecret, profile, done) => {
      try {
        if (profile.emails && profile.emails.length)
          profile.emails[0].verified = true;
        const user = await login(req, 'twitter', profile, {
          token,
          tokenSecret,
        });
github kriasoft / nodejs-api-starter / src / passport.js View on Github external
`${profile.name.givenName} ${profile.name.familyName}`;
        const user = await login(req, 'facebook', profile, {
          accessToken,
          refreshToken,
        });
        done(null, user);
      } catch (err) {
        done(err);
      }
    },
  ),
);

// https://github.com/jaredhanson/passport-twitter
passport.use(
  new TwitterStrategy(
    {
      consumerKey: process.env.TWITTER_KEY,
      consumerSecret: process.env.TWITTER_SECRET,
      callbackURL: '/login/twitter/return',
      includeEmail: true,
      includeStatus: false,
      passReqToCallback: true,
    },
    async (req, token, tokenSecret, profile, done) => {
      try {
        if (profile.emails && profile.emails.length)
          profile.emails[0].verified = true;
        const user = await login(req, 'twitter', profile, {
          token,
          tokenSecret,
        });
github fossasia / loklak_walls / server / index.js View on Github external
app.use(session({
    secret: 'keyboard cat',
    resave: true,
    saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());

passport.serializeUser(function(user, done) {
    done(null, user);
});
passport.deserializeUser(function(obj, done) {
    done(null, obj);
});

passport.use(new TwitterStrategy({
        consumerKey: config.twitterConsumerKey,
        consumerSecret: config.twitterConsumerSecret,
        callbackURL: config.twitterCallbackUrl
    },
    function(token, tokenSecret, profile, done) {
        process.nextTick(function() {
        	console.log(token);
        	console.log(tokenSecret);
            profile.oauth_token = token;
            profile.oauth_token_secret = tokenSecret;
            return done(null, profile);
        });
    }
));

app.get('/account', ensureAuthenticated, function(req, res) {

passport-twitter

Twitter authentication strategy for Passport.

MIT
Latest version published 8 years ago

Package Health Score

50 / 100
Full package analysis

Popular passport-twitter functions