/passport-ping

Passport strategy for authenticating with PingFederate using the OAuth 2.0 API

Primary LanguageJavaScript

Passport-Ping

Passport strategy for authenticating with PingFederate using the OAuth 2.0 API. This assumes you have a properly configured and running PingFederate server.

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

Install

$ npm install passport-ping

Usage

Configure Strategy

The PingFederate authentication strategy authenticates users using PingFederate and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a host, port, client ID, client secret, and callback URL.

passport.use(new PingStrategy({
    clientID: '123-456-789' ,
    clientSecret: 'shhh-its-a-secret' ,
    callbackURL: 'https://www.example.net/auth/ping/callback'
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate(..., function (err, user) {
      return done(err, user);
    });
  }
));

passport.use(new PingStrategy({
    host: 'localhost' ,
    clientID: '123-456-789' ,
    clientSecret: 'shhh-its-a-secret' ,
    callbackURL: 'https://www.example.net/auth/ping/callback'
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate(..., function (err, user) {
      return done(err, user);
    });
  }
));

passport.use(new PingStrategy({
    host: 'localhost' ,
    port: 9031 ,
    clientID: '123-456-789' ,
    clientSecret: 'shhh-its-a-secret' ,
    callbackURL: 'https://www.example.net/auth/ping/callback'
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate(..., function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

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

Credits

License

The MIT License