passport-ldsauth

LDSAuth.org / LDS.org authentication strategy for Passport and Node.js

passport-ldsauth

================

Passport strategy for authenticating with LDSAuth.org / LDS.org using the OAuth 2.0 API.

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

npm install passport-ldsauth --save

The LDSAuth authentication strategy authenticates users using an LDS.org account 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 app ID, app secret, and callback URL.

passport.use(new LdsAuthStrategy({
    clientID: LDSAUTH_APP_ID,
    clientSecret: LDSAUTH_APP_SECRET,
    callbackURL: "http://localhost:3000/oauth2/ldsauth/callback"
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ ldsOrgId: profile.currentUserId }, function (err, user) {
      return done(err, user);
    });
  }
));

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

For example, as route middleware in an Express application:

app.get(
  '/oauth2/ldsauth'
, passport.authenticate('ldsauth')
);
 
// On success this falls through to the second route 
app.get(
  '/oauth2/ldsauth/callback'
, passport.authenticate('ldsauth', { failureRedirect: '/login' })
);
app.get(
  '/oauth2/ldsauth/callback'
, function (reqres) {
    // Successful authentication, redirect home. 
    res.redirect('/');
  }
);

The MIT License

Copyright (c) 2014 AJ ONeal <http://coolaj86.com/>