1.8.0 • Published 1 year ago

passport-oauth2 v1.8.0

Weekly downloads
333,372
License
MIT
Repository
github
Last release
1 year ago

passport-oauth2

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-based sign in 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.

:brain: Understanding OAuth 2.0 • :heart: Sponsors



npm build coverage ...

Install

$ npm install passport-oauth2

Usage

Configure Strategy

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 cb providing a user.

passport.use(new OAuth2Strategy({
    authorizationURL: 'https://www.example.com/oauth2/authorize',
    tokenURL: 'https://www.example.com/oauth2/token',
    clientID: EXAMPLE_CLIENT_ID,
    clientSecret: EXAMPLE_CLIENT_SECRET,
    callbackURL: "http://localhost:3000/auth/example/callback"
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ exampleId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

app.get('/auth/example',
  passport.authenticate('oauth2'));

app.get('/auth/example/callback',
  passport.authenticate('oauth2', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Related Modules

Contributing

Tests

The test suite is located in the test/ directory. All new features are expected to have corresponding test cases. Ensure that the complete test suite passes by executing:

$ make test

Coverage

All new feature development is expected to have test coverage. Patches that increse test coverage are happily accepted. Coverage reports can be viewed by executing:

$ make test-cov
$ make view-cov

License

The MIT License

Copyright (c) 2011-2016 Jared Hanson [http://jaredhanson.net/](http://jaredhanson.net/)

hadith-apppassport-likecoin@ajayaldo/passport-cognito-oauth2passport-aws-cognito-oauth2passport-twitch-v5node-vk-auth-apinode-vkauther-prism-webfishsouptest-test-test-fishs@mirohq/passport-miro@juris710/passport-slackpassport-pushbulletsynaptix.js@open-cluster-management/security-middlewaresurf2gather-backendpassport-act-onpassport-mykoobpassport-omgauthpassport-windowslive-contactsinfinity-oauth@infinitebrahmanuniverse/nolb-passport-o@paiondata/nextwikipassport-authsiderpassport-monzotwitch-oauth-passport@everything-registry/sub-chunk-2414tensowiki-security-passportjssportily-react-scriptsth-passport-linkedin-oauth2ticket-pleasevkontakte-passportvaltechonepage@dmapper/passport-idg-oauth2@d-fischer/passport-twitch@dal/dftr-api@datacentricdesign/sdk-js@datacentricdesign/bucket-api@datacentricdesign/sdk@boomee/api@perimetre/nextjs-auth@ruibaby/wiki@roothub/nr-launcherkayzkuzzle-plugin-auth-githubkuzzle-plugin-auth-passport-oauthpassport-facebook-rwkystfstf-patchedstf-private-testingtwitch-passporttixte-passporttriz-passport-kakaotry-is-even@aoberoi/passport-slack@aptly-as/passport-sso@atlassian-partner-engineering/passport-bitbucket-oauth2@authajs/passport-autha@agyemanjp/passport-digitalocean@agyemanjp/passport-heroku@ahextechnology/social-handles@afermon/passport-microsoft@aehrt-fifty-five/passport-shopline@alexjv89/microlight@akryum/passport-slack-oauth2@allanoricil/nr-launcher@alpine-code/node-red@backstage/plugin-auth-backend-module-vmware-cloud-provider@backstage/plugin-auth-backend-module-guest-provider@backstage/plugin-auth-backend-module-oauth2-provider@backstage/plugin-auth-backend@backstage/plugin-auth-backend-module-auth0-provider@backstage/plugin-auth-backend-module-bitbucket-server-provider@bartvanvliet/passport-microsoft@azekia/passport-twitch@ambergg/passport-faceit@bleco/authentication@blitzritz/passport-microsoft@carmel/sdk@cabloy/core@cloudentity/passport-oauth2@0xgw/passport-forcedotcom@1000ship/passport-kakao@3tatsu/passport-discord3chospirits-passport-google-oauth201000-packages@activelylearn/passport-clever-oauth20@acceleratxr/passport-discord-token@starpad/server@boklisten/bl-api@devjoyvn/passport-oneauth@devicefarmer/stf@diekeure/passport-smartschool@digifi/periodicjs.ext.oauth2client@davidzemon/passport-okta-oauthyahoo-contactsy9-passport-weixinyourlocalcousinxoob-passport-shopifyzwx-passport-weixin
1.8.0

1 year ago

1.7.0

2 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.0

6 years ago

1.4.0

8 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.2

11 years ago

1.1.1

12 years ago

1.1.0

12 years ago

1.0.0

12 years ago