JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q42079F
  • License MIT

Passport Strategy for Twitter API v2

Package Exports

  • passport-twitter-2
  • passport-twitter-2/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (passport-twitter-2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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