@omneedia/passport-oauth2

1.0.0 • Public • Published

passport-oauth2

General-purpose OAuth 2.0 ADFS 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 OAuth 2.0 support for ADFS.

Install

$ npm install https://github.com/vanildo/passport-oauth2-adfs.git

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

passport.use(new OAuth2Strategy({
  authorizationURL: 'https://adfsServer/adfs/oauth2/authorize',
  resource: 'https://app/auth/sso/callback',
  tokenURL: 'https://adfsServer/adfs/oauth2/token',
  clientID: 'CLIENT_ID',
  clientSecret: 'EXAMPLE_CLIENT_SECRET',
  callbackURL: 'https://app/auth/sso/callback'
},
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ exampleId: profile.id }, function (err, user) {
      return done(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

Tests

$ npm install
$ npm test

Credits

License

The MIT License

Package Sidebar

Install

npm i @omneedia/passport-oauth2

Weekly Downloads

0

Version

1.0.0

License

none

Unpacked Size

149 kB

Total Files

28

Last publish

Collaborators

  • stephane.zucatti