OAuth 2.0 authentication strategy for Passport.


General-purpose OAuth 2.0 authentication strategy for Passport.

This module lets you authenticate using OAuth 2.0 in your Node.js applications. By plugging into Passport, OAuth 2.0 authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Note that this strategy provides generic OAuth 2.0 support. In many cases, a provider-specific strategy can be used instead, which cuts down on unnecessary configuration, and accommodates any provider-specific quirks. See the list for supported providers.

Developers who need to implement authentication against an OAuth 2.0 provider that is not already supported are encouraged to sub-class this strategy. If you choose to open source the new provider-specific strategy, please add it to the list so other people can find it.

$ npm install passport-oauth2

The OAuth 2.0 authentication strategy authenticates users using a third-party account and OAuth 2.0 tokens. The provider's OAuth 2.0 endpoints, as well as the client identifer and secret, are specified as options. The strategy requires a verify callback, which receives an access token and profile, and calls done providing a user.

passport.use(new OAuth2Strategy({
    authorizationURL: '',
    tokenURL: '',
    clientSecret: EXAMPLE_CLIENT_SECRET,
    callbackURL: "http://localhost:3000/auth/example/callback"
  function(accessTokenrefreshTokenprofiledone) {
    User.findOrCreate({ exampleId: }, function (erruser) {
      return done(err, user);

Use passport.authenticate(), specifying the 'oauth2' strategy, to authenticate requests.

For example, as route middleware in an Express application:

  passport.authenticate('oauth2', { failureRedirect: '/login' }),
  function(reqres) {
    // Successful authentication, redirect home. 
$ npm install
$ npm test

The MIT License

Copyright (c) 2011-2015 Jared Hanson <>