passport-facebook vs passport-github vs passport-google-oauth20 vs passport-linkedin-oauth2 vs passport-oauth vs passport-oauth2 vs passport-twitter
Implementing Social Authentication Strategies in Node.js
passport-facebookpassport-githubpassport-google-oauth20passport-linkedin-oauth2passport-oauthpassport-oauth2passport-twitterSimilar Packages:

Implementing Social Authentication Strategies in Node.js

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.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
passport-facebook01,309-1308 years agoMIT
passport-github0536-2111 years agoMIT
passport-google-oauth200836-587 years agoMIT
passport-linkedin-oauth2012226.3 kB47-MIT
passport-oauth0117-813 years ago-
passport-oauth2061736.6 kB963 years agoMIT
passport-twitter0466-3411 years agoMIT

Social Authentication Strategies: Protocol, Setup, and Maintenance

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.

🔐 Protocol Versions: OAuth 1.0a vs OAuth 2.0

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.

  • They rely on bearer tokens.
  • Secrets are sent only during the token exchange, not with every request.
  • Easier to implement in single-page apps.
// 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.

  • Use this when a specific provider package does not exist.
  • Requires manual definition of authorization and token URLs.
// 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.

  • Requires signing every request with a consumer secret.
  • More complex cryptographic handling.
  • Twitter v1.1 uses this; Twitter v2 uses OAuth 2.0.
// 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));

⚙️ Configuration Complexity

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)

  • Minimal config: just keys, secrets, and callback URL.
  • Profile URLs are handled internally.
// 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)

  • Higher config: must define all endpoint URLs.
  • Risk of misconfiguration if endpoints change.
// 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));

👤 Profile Data Retrieval

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);
});

⚠️ Maintenance and API Changes

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.

📊 Summary Table

PackageProtocolUse CaseMaintenance Status
passport-facebookOAuth 2.0Facebook Login✅ Active
passport-githubOAuth 2.0GitHub Login✅ Active
passport-google-oauth20OAuth 2.0Google Login✅ Active
passport-linkedin-oauth2OAuth 2.0LinkedIn Login✅ Active
passport-oauthOAuth 1.0Legacy Custom⚠️ Legacy
passport-oauth2OAuth 2.0Custom Provider✅ Active
passport-twitterOAuth 1.0aTwitter Login (v1.1)⚠️ Legacy API

💡 Final Recommendation

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.

How to Choose: passport-facebook vs passport-github vs passport-google-oauth20 vs passport-linkedin-oauth2 vs passport-oauth vs passport-oauth2 vs passport-twitter

  • passport-facebook:

    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.

  • passport-github:

    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.

  • passport-google-oauth20:

    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.

  • passport-linkedin-oauth2:

    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.

  • passport-oauth:

    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.

  • passport-oauth2:

    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.

  • passport-twitter:

    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.

README for passport-facebook

passport-facebook

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.


Status: Build Coverage Quality Dependencies

Install

$ npm install passport-facebook

Usage

Create an Application

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.

Configure Strategy

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);
    });
  }
));

Authenticate Requests

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('/');
  });

Examples

Developers using the popular Express web framework can refer to an example as a starting point for their own web applications.

FAQ

How do I ask a user for additional permissions?

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.

How do I re-ask for for declined permissions?

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.

How do I obtain a user profile with specific fields?

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.

How do I include app secret proof in API requests?

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.

Why is #_=_ appended to the redirect URI?

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.

Sponsorship

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.

License

The MIT License

Copyright (c) 2011-2016 Jared Hanson <http://jaredhanson.net/>