Passport strategy for authenticating with ThingsFactory using the OAuth 2.0 API.
This module lets you authenticate using ThingsFactory in your Node.js applications. By plugging into Passport, ThingsFactory authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
npm install -S passport-things-factory
NOTE: Unlike other OAuth2 passport strategies, this requires a specific site
if you want it to be dynamic.
The ThingsFactory authentication strategy authenticates users using a ThingsFactory 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 client ID, client secret, and callback URL.
Static site Name:
passport.use(
new ThingsFactoryStrategy(
{
clientID: THINGS_FACTORY_CLIENT_ID,
clientSecret: THINGS_FACTORY_CLIENT_SECRET,
callbackURL: 'http://127.0.0.1:3000/auth/things-factory/callback',
site: THINGS_FACTORY_site_SLUG // e.g. my-site-name.operato.com ... the `my-site-name` part
},
function (accessToken, refreshToken, profile, done) {
User.findOrCreate({ thingsFactoryId: profile.id }, function (err, user) {
return done(err, user)
})
}
)
)
Dynamic site Name:
See example folder.
Use passport.authenticate()
, specifying the 'things-factory'
strategy, to
authenticate requests.
For example, as route middleware in an Express application:
app.get(
'/auth/things-factory',
passport.authenticate('things-factory', {
scope: ['read_products'],
site: 'site-name'
})
)
app.get(
'/auth/things-factory/callback',
passport.authenticate('things-factory', { failureRedirect: '/login' }),
function (req, res) {
// Successful authentication, redirect home.
res.redirect('/')
}
)
For a complete, working example, refer to the example.
npm install -d
npm run test
Copyright (c) 2011-2016 Dantheta and Nick Baugh