JSPM

passport-ping-oauth2

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 364
  • Score
    100M100P100Q96668F
  • License ISC

Ping OAuth 2.0 authentication strategy for Passport.

Package Exports

  • passport-ping-oauth2

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (passport-ping-oauth2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

passport-ping-oauth2

PingFederate OAuth 2.0 authentication strategy for Passport.

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

Install

$ npm install passport-ping-oauth2

Usage

Configure Strategy

The Ping authentication strategy authenticates users using a Ping account and OAuth 2.0 tokens. Ping'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://www.example.com/as/authorization.oauth2',
    tokenURL: 'https://www.example.com/as/token.oauth2',
    clientID: EXAMPLE_CLIENT_ID,
    clientSecret: EXAMPLE_CLIENT_SECRET,
    callbackURL: "http://localhost:3000/auth/oauth2/callback'
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOne({ 'ping.id' : profile.id }, function (err, user) {
        if (err) { return done(err); }
        if (user) {
            return done(null, user);
        } else {
            var newUser = new User();
            newUser.ping.id    = profile.id;
            newUser.ping.token = accessToken;
            newUser.ping.name  = profile.displayName;
            newUser.ping.email = profile.email;
            newUser.save(function(err) {
                if (err) { throw err; }
                return done(null, newUser);
            });
        }
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

app.get('/auth/oauth2',
    passport.authenticate('oauth2', { scope : ['openid', 'profile', 'email'] }));

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

Tests

$ npm install
$ npm test

Credits

License

The MIT License