passport-freshbooks

0.1.0 • Public • Published

Passport-Freshbooks

Passport strategy for authenticating with Freshbooks using the OAuth 1.0a API.

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

This module is a straight copy/paste from Jared Hanson's excellent Passport LinkedIn module.

LinkedIn and Freshbooks both use oAuth1.0a so it seemed like a good place to start.

Install

$ npm install passport-freshbooks

Usage

Configure Strategy

For a working example, see ./examples/login/app.js.

The Freshbooks authentication strategy authenticates users using a Freshbooks account and OAuth tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a consumer key, consumer secret, and callback URL.

passport.use(new FreshbooksStrategy({

    // This is your Freshbooks subdomain.  e.g. `example` in `http://example.freshbooks.com`
    consumerKey: SUBDOMAIN,

    // This is your OAuth Secret from My Account -> Freshbooks API.
    consumerSecret: FRESHBOOKS_OAUTH_SECRET,

    // This callback needs to be the same servername as the app.  localhost != 127.0.0.1
    callbackURL: "http://127.0.0.1:3000/auth/freshbooks/callback"
  },
  function(token, tokenSecret, profile, done) {
    User.findOrCreate({ freshbooksId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

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

Profile Fields

The Freshbooks profile contains a lot of information.

See ./examples/login/views/account.ejs and ./examples/login/app.js for more info

Examples

For a complete, working example, refer to the login example.

Credits

License

The MIT License

Copyright (c) 2013 Michael Cole <http://powma.com/>

Readme

Keywords

none

Package Sidebar

Install

npm i passport-freshbooks

Weekly Downloads

0

Version

0.1.0

License

none

Last publish

Collaborators

  • michaelcole