Socket
Socket
Sign inDemoInstall

passport-twitter-2

Package Overview
Dependencies
10
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    passport-twitter-2

Passport Strategy for Twitter API v2


Version published
Weekly downloads
7
Maintainers
1
Install size
8.90 MB
Created
Weekly downloads
 

Readme

Source

Passport-Twitter-2

Passport strategy for authenticating with Twitter API v2

Install

npm install passport-twitter-2

Usage

Configure Strategy
import { Strategy as TwitterStrategy } from 'passport-twitter-2';
passport.use(new TwitterStrategy({
    clientID: TWITTER_CLIENT_ID,
    appKey: TWITTER_CLIENT_SECRET,
    callbackURL: "http://localhost:3000/auth/twitter/callback"
  },
  function(accessToken, profile, done) {
    User.findOrCreate({ twitter: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));
Authenticate Requests

Use passport.authenticate(), specifying the 'twitter' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/twitter',
  passport.authenticate('twitter'));

app.get('/auth/twitter/callback',
  passport.authenticate('twitter', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Notes

For Node.js 18+ you can skip installing node-fetch with

npm i passport-twitter-2 --omit=optional

and use built-in fetch instead.

Credits

License

The MIT License

Copyright (c) 2022 Ēriks Remess

Keywords

FAQs

Last updated on 19 Aug 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc