Passport-Torchlite

Passport strategy for authenticating with Torchlite using the OAuth 2.0 API.

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

Install

$ npm i passport-torchlite

Usage

Create an Application

Before using passport-torchlite, you mush register an application with Torchlite. If you would like to register a new application please email dmccormick@torchlite.com with details about your application. Once your application has been approved you will be issues a clientId and clientSecret. You will also need to specify a redirect URI which matches the route in your application.

Configure Strategy

The Torchlite authentication strategy authenticates users using a Torchlite account and OAuth 2.0 tokens. The clientId and clientSecret obtained when creating an application are supplied as options when creating the strategy. The strategy also requires a verify callback, which receives the access token and optional refresh token, as well as profile which contains the authenticated user's Facebook profile. The verify callback must call cb providing a user to complete authentication.

passport.use(new TorchliteStrategy({
    clientID: TORCHLITE_CLIENT_ID,
    clientSecret: TORCHLITE_CLIENT_SECRET ,
    callbackURL: "http://localhost:3000/auth/torchlite/callback"
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ torchliteId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

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

License

The MIT License

Copyright (c) Torchlite

SEARCH FOR STRATEGIES

0STRATEGIES