This comparison evaluates seven Passport.js strategies used to integrate social login providers into Node.js applications. The packages cover both OAuth 1.0a and OAuth 2.0 protocols, enabling authentication via major platforms like Facebook, GitHub, Google, LinkedIn, and Twitter. While specific strategies simplify setup for known providers, generic strategies offer flexibility for custom or less common services. Understanding the protocol differences and maintenance status of each package is critical for building secure and sustainable authentication flows.
Passport.js strategies simplify adding social login to Node.js apps, but they differ significantly in protocol support and maintenance. passport-facebook, passport-github, passport-google-oauth20, passport-linkedin-oauth2, and passport-twitter are provider-specific wrappers. passport-oauth and passport-oauth2 are generic base classes for OAuth 1.0 and OAuth 2.0 respectively. Let's compare how they handle authentication flows, configuration, and data retrieval.
The most critical technical distinction is the underlying protocol. OAuth 2.0 is the modern standard, while OAuth 1.0a is legacy but still in use by some providers like Twitter (for v1.1 APIs).
passport-facebook, passport-github, passport-google-oauth20, and passport-linkedin-oauth2 all use OAuth 2.0.
// passport-facebook (OAuth 2.0)
passport.use(new FacebookStrategy({ clientID, clientSecret, callbackURL }, verify));
// passport-github (OAuth 2.0)
passport.use(new GitHubStrategy({ clientID, clientSecret, callbackURL }, verify));
// passport-google-oauth20 (OAuth 2.0)
passport.use(new GoogleStrategy({ clientID, clientSecret, callbackURL }, verify));
// passport-linkedin-oauth2 (OAuth 2.0)
passport.use(new LinkedInStrategy({ clientID, clientSecret, callbackURL }, verify));
passport-oauth2 is the generic base for OAuth 2.0.
// passport-oauth2 (Generic OAuth 2.0)
passport.use(new OAuth2Strategy({
authorizationURL: 'https://provider.com/oauth/authorize',
tokenURL: 'https://provider.com/oauth/token',
clientID, clientSecret, callbackURL
}, verify));
passport-twitter and passport-oauth use OAuth 1.0a.
// passport-twitter (OAuth 1.0a)
passport.use(new TwitterStrategy({ consumerKey, consumerSecret, callbackURL }, verify));
// passport-oauth (Generic OAuth 1.0)
passport.use(new OAuthStrategy({
requestTokenURL: 'https://provider.com/oauth/request_token',
accessTokenURL: 'https://provider.com/oauth/access_token',
consumerKey, consumerSecret, callbackURL
}, verify));
Provider-specific packages reduce boilerplate by hardcoding standard URLs. Generic packages require you to look up and configure these endpoints manually.
Provider-Specific (Facebook, GitHub, Google, LinkedIn, Twitter)
// passport-facebook
passport.use(new FacebookStrategy({
clientID: process.env.FB_ID,
clientSecret: process.env.FB_SECRET,
callbackURL: "/auth/facebook/callback"
}, callback));
// passport-github
passport.use(new GitHubStrategy({
clientID: process.env.GH_ID,
clientSecret: process.env.GH_SECRET,
callbackURL: "/auth/github/callback"
}, callback));
// passport-google-oauth20
passport.use(new GoogleStrategy({
clientID: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET,
callbackURL: "/auth/google/callback"
}, callback));
// passport-linkedin-oauth2
passport.use(new LinkedInStrategy({
clientID: process.env.LI_ID,
clientSecret: process.env.LI_SECRET,
callbackURL: "/auth/linkedin/callback"
}, callback));
// passport-twitter
passport.use(new TwitterStrategy({
consumerKey: process.env.TWITTER_KEY,
consumerSecret: process.env.TWITTER_SECRET,
callbackURL: "/auth/twitter/callback"
}, callback));
Generic (passport-oauth, passport-oauth2)
// passport-oauth2
passport.use(new OAuth2Strategy({
authorizationURL: 'https://api.example.com/oauth/authorize',
tokenURL: 'https://api.example.com/oauth/token',
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: "/auth/callback"
}, callback));
// passport-oauth
passport.use(new OAuthStrategy({
requestTokenURL: 'https://api.example.com/oauth/request_token',
accessTokenURL: 'https://api.example.com/oauth/access_token',
userAuthorizationURL: 'https://api.example.com/oauth/authorize',
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
callbackURL: "/auth/callback"
}, callback));
Each strategy returns a profile object to the verify callback. The structure varies by provider, affecting how you map user data to your database.
Facebook, Google, LinkedIn typically provide rich profile data (email, name, photos) by default or via scopes.
// passport-facebook
FacebookStrategy(..., (accessToken, refreshToken, profile, cb) => {
// profile.emails, profile.photos, profile.displayName
return cb(null, profile);
});
// passport-google-oauth20
GoogleStrategy(..., (accessToken, refreshToken, profile, cb) => {
// profile.emails, profile.photos, profile.displayName
return cb(null, profile);
});
// passport-linkedin-oauth2
LinkedInStrategy(..., (accessToken, refreshToken, profile, cb) => {
// profile.emails, profile.photos, profile.displayName
return cb(null, profile);
});
GitHub focuses on developer identity; email might be private unless scoped.
// passport-github
GitHubStrategy(..., (accessToken, refreshToken, profile, cb) => {
// profile.emails (may be empty if not public)
return cb(null, profile);
});
Twitter (OAuth 1.0a) passes token and tokenSecret which must be stored if you plan to tweet on behalf of the user.
// passport-twitter
TwitterStrategy(..., (token, tokenSecret, profile, cb) => {
// Must store token and tokenSecret for API calls
return cb(null, profile);
});
Generic Strategies return raw data that you must parse manually.
// passport-oauth2
OAuth2Strategy(..., (accessToken, refreshToken, profile, cb) => {
// profile might be undefined; you may need to fetch it manually
return cb(null, profile);
});
// passport-oauth
OAuthStrategy(..., (token, tokenSecret, profile, cb) => {
// Similar to Twitter, handles OAuth 1.0 tokens
return cb(null, profile);
});
Provider APIs change frequently. Using a specific package means relying on the maintainer to update the strategy when endpoints change.
passport-twitter: Twitter is deprecating API v1.1. New apps should evaluate OAuth 2.0 options (passport-twitter-oauth2 exists but is not in this list). The classic passport-twitter package works but may face limitations on new developer accounts.passport-linkedin-oauth2: LinkedIn migrated to v2 API. Ensure you use the oauth2 package, not the legacy passport-linkedin.passport-google-oauth20: Google frequently updates security policies. This package is well-maintained to reflect those changes.passport-oauth / passport-oauth2: These are stable base classes. They do not break when providers change URLs, but your config might need updates.| Package | Protocol | Use Case | Maintenance Status |
|---|---|---|---|
passport-facebook | OAuth 2.0 | Facebook Login | ✅ Active |
passport-github | OAuth 2.0 | GitHub Login | ✅ Active |
passport-google-oauth20 | OAuth 2.0 | Google Login | ✅ Active |
passport-linkedin-oauth2 | OAuth 2.0 | LinkedIn Login | ✅ Active |
passport-oauth | OAuth 1.0 | Legacy Custom | ⚠️ Legacy |
passport-oauth2 | OAuth 2.0 | Custom Provider | ✅ Active |
passport-twitter | OAuth 1.0a | Twitter Login (v1.1) | ⚠️ Legacy API |
For new projects, prioritize OAuth 2.0 strategies. Use passport-facebook, passport-github, passport-google-oauth20, or passport-linkedin-oauth2 for their respective platforms to minimize configuration errors. If you need to support a provider without a specific package, extend passport-oauth2.
Avoid passport-oauth (OAuth 1.0) unless you are maintaining legacy integrations. Be cautious with passport-twitter as Twitter pushes developers toward OAuth 2.0 for API v2; verify if your use case requires the older v1.1 endpoints before committing.
Key Takeaway: Specific packages save time and reduce risk. Generic packages offer flexibility but require deeper knowledge of the provider's API documentation.
Choose passport-facebook when implementing login via Facebook accounts. It handles the OAuth 2.0 flow specific to Facebook's Graph API, including permission scopes for email and public profile. This package is stable and widely used for consumer-facing apps targeting Facebook users. Ensure you configure the correct API version to avoid deprecation issues.
Choose passport-github for applications requiring developer-centric authentication. It supports OAuth 2.0 and allows scoping for read-only user data or repository access. This is the standard choice for tools targeting developers or open-source projects. It is lightweight and focuses strictly on GitHub identity verification.
Choose passport-google-oauth20 for Google account integration. It supports OAuth 2.0 and handles Google's specific token endpoints and profile structures. This package is essential for apps needing access to Google services like Gmail or Drive alongside authentication. It is actively maintained to match Google's security updates.
Choose passport-linkedin-oauth2 for professional network authentication. It implements OAuth 2.0 compatible with LinkedIn's v2 API, which replaced the older v1 endpoints. Use this when targeting professional demographics or needing verified employment data. Be aware of LinkedIn's stricter scope approval processes for production apps.
Choose passport-oauth only for legacy systems requiring OAuth 1.0a where no specific strategy exists. It provides the base implementation for signing requests with consumer secrets. This package is rarely needed for new projects since most providers have moved to OAuth 2.0. Use it with caution as OAuth 1.0a is considered outdated.
Choose passport-oauth2 when building a custom strategy for an OAuth 2.0 provider without an official package. It gives you full control over authorization and token endpoints. This is ideal for enterprise SSO or niche providers. It requires more manual configuration but offers maximum flexibility.
Choose passport-twitter for legacy Twitter API v1.1 authentication using OAuth 1.0a. Note that Twitter is shifting to OAuth 2.0 for API v2, but this package remains the standard for the classic login flow. Use this if you rely on existing Twitter integrations that have not migrated to v2. Evaluate migration paths as Twitter updates its developer policies.
Passport strategy for authenticating with Facebook using the OAuth 2.0 API.
This module lets you authenticate using Facebook in your Node.js applications. By plugging into Passport, Facebook authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
1Password, the only password manager you should trust. Industry-leading security and award winning design.
$ npm install passport-facebook
Before using passport-facebook, you must register an application with
Facebook. If you have not already done so, a new application can be created at
Facebook Developers. Your application will
be issued an app ID and app secret, which need to be provided to the strategy.
You will also need to configure a redirect URI which matches the route in your
application.
The Facebook authentication strategy authenticates users using a Facebook
account and OAuth 2.0 tokens. The app ID and 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 optional
refresh token, as well as profile which contains the authenticated user's
Facebook profile. The verify callback must call cb providing a user to
complete authentication.
passport.use(new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "http://localhost:3000/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, cb) {
User.findOrCreate({ facebookId: profile.id }, function (err, user) {
return cb(err, user);
});
}
));
Use passport.authenticate(), specifying the 'facebook' strategy, to
authenticate requests.
For example, as route middleware in an Express application:
app.get('/auth/facebook',
passport.authenticate('facebook'));
app.get('/auth/facebook/callback',
passport.authenticate('facebook', { 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.
If you need additional permissions from the user, the permissions can be
requested via the scope option to passport.authenticate().
app.get('/auth/facebook',
passport.authenticate('facebook', { scope: ['user_friends', 'manage_pages'] }));
Refer to permissions with Facebook Login for further details.
Set the authType option to reauthenticate when authenticating.
app.get('/auth/facebook',
passport.authenticate('facebook', { authType: 'reauthenticate', scope: ['user_friends', 'manage_pages'] }));
Refer to re-asking for declined permissions for further details.
The Facebook profile contains a lot of information about a user. By default,
not all the fields in a profile are returned. The fields needed by an application
can be indicated by setting the profileFields option.
new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "http://localhost:3000/auth/facebook/callback",
profileFields: ['id', 'displayName', 'photos', 'email']
}), ...)
Refer to the User section of the Graph API Reference for the complete set of available fields.
Set the enableProof option when creating the strategy.
new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "http://localhost:3000/auth/facebook/callback",
enableProof: true
}, ...)
As detailed in securing graph API requests, requiring the app secret for server API requests helps prevent use of tokens stolen by malicous software or man in the middle attacks.
This behavior is "by design" according to Facebook's response to a bug filed regarding this issue.
Fragment identifiers are not supplied in requests made to a server, and as such this strategy is not aware that this behavior is exhibited and is not affected by it. If desired, this fragment can be removed on the client side. Refer to this discussion on Stack Overflow for recommendations on how to accomplish such removal.
Passport is open source software. Ongoing development is made possible by generous contributions from individuals and corporations. To learn more about how you can help keep this project financially sustainable, please visit Jared Hanson's page on Patreon.
Copyright (c) 2011-2016 Jared Hanson <http://jaredhanson.net/>