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.
@superfaceai/passport-twitter-oauth2
Advanced tools
Twitter OAuth 2.0 authentication strategy for Passport.
@superfaceai/passport-twitter-oauth2
Passport strategy for authenticating with Twitter using OAuth 2.0.
This module lets you authenticate using Twitter in your Node.js applications. By plugging into Passport, Twitter authentication can be integrated into any application or framework that supports Connect-style middleware, including Express.
Twitter announced OAuth 2.0 general availability on December 14 2021 and encourages developers to use Twitter API v2.0 with OAuth 2.0 authentication.
Twitter OAuth 2.0 implementation specifics:
Authorization
header for confidential
client typesnpm install @superfaceai/passport-twitter-oauth2
Note Check our blog for a complete tutorial with code explanation.
Before using @superfaceai/passport-twitter-oauth2
, you must register a project and an application with Twitter by following these steps:
Provide OAuth 2.0 Client ID and Client Secret (from previous step)
to the strategy constructor. The strategy
also requires a verify
callback, which receives the access token and
refresh token 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(
{
clientType: 'confidential', //depends on your Twitter app settings, valid values are `confidential` or `public`
clientID: TWITTER_CLIENT_ID,
clientSecret: TWITTER_CLIENT_SECRET,
callbackURL: 'http://127.0.0.1:3000/auth/twitter/callback',
},
function (accessToken, refreshToken, profile, done) {
User.findOrCreate({ twitterId: profile.id }, function (err, user) {
return done(err, user);
});
}
)
);
Use passport.authenticate()
, specifying the 'twitter'
strategy, to
authenticate requests.
Do not forget to configure scopes required by your application.
For example, you can use authenticate
function as an Express route middleware:
app.get('/auth/twitter', passport.authenticate('twitter'));
app.get(
'/auth/twitter/callback',
passport.authenticate('twitter', {
failureRedirect: '/login',
scope: ['tweet.read', 'tweet.write', 'users.read'],
}),
function (req, res) {
// Successful authentication, redirect home.
res.redirect('/');
}
);
Check the examples directory for minimal working projects:
When developing, start with cloning the repository using git clone https://github.com/superfaceai/passport-twitter-oauth2.git
.
After cloning, install the dependencies with npm i
.
Now the repository is ready for code changes.
The package.json
also contains scripts (runnable by calling npm run <script-name>
):
build
- transpile TypeScript into JavaScriptformat
- check the code formattingformat:fix
- fix the code formattinglint
- run lintertest
- run testsPlease open an issue first if you want to make larger changes
Feel free to contribute! Please follow the Contribution Guide.
@superfaceai/passport-twitter-oauth2
project is licensed under the MIT license.
© 2023 Superface s.r.o.
FAQs
Twitter OAuth 2.0 authentication strategy for Passport.
The npm package @superfaceai/passport-twitter-oauth2 receives a total of 2,924 weekly downloads. As such, @superfaceai/passport-twitter-oauth2 popularity was classified as popular.
We found that @superfaceai/passport-twitter-oauth2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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.