Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@passport-js/passport-twitter
Advanced tools
Passport strategy for authenticating with Twitter using the OAuth 1.0a API.
This module lets you authenticate using Twitter in your Node.js applications. By plugging into Passport, Twitter authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
:heart: Sponsors
Advertisement
The Complete Node.js Developer Course
Learn Node. js by building real-world applications with Node, Express, MongoDB, Jest, and more!
$ npm i @passport-js/passport-twitter
Before using passport-twitter
, you must register an application with Twitter.
If you have not already done so, a new application can be created at
Twitter Application Management. Your application
will be issued a consumer key (API Key) and consumer secret (API Secret), which
need to be provided to the strategy. You will also need to configure a callback
URL which matches the route in your application.
The Twitter authentication strategy authenticates users using a Twitter account
and OAuth tokens. The consumer key and consumer secret obtained when creating
an application are supplied as options when creating the strategy. The strategy
also requires a verify
callback, which receives the access token and
corresponding secret as arguments, as well as profile
which contains the
authenticated user's Twitter profile. The verify
callback must call cb
providing a user to complete authentication.
passport.use(new TwitterStrategy({
consumerKey: TWITTER_CONSUMER_KEY,
consumerSecret: TWITTER_CONSUMER_SECRET,
callbackURL: "http://127.0.0.1:3000/auth/twitter/callback"
},
function(token, tokenSecret, profile, cb) {
User.findOrCreate({ twitterId: profile.id }, function (err, user) {
return cb(err, user);
});
}
));
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('/');
});
Developers using the popular Express web framework can refer to an example as a starting point for their own web applications.
Copyright (c) 2011-2016 Jared Hanson <http://jaredhanson.net/>
FAQs
Twitter authentication strategy for Passport.
The npm package @passport-js/passport-twitter receives a total of 139 weekly downloads. As such, @passport-js/passport-twitter popularity was classified as not popular.
We found that @passport-js/passport-twitter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.