Skip to content

NodeJS PassportJS OAuth library for Freshbooks. Based on passport-linkedin

License

Notifications You must be signed in to change notification settings

MichaelJCole/passport-freshbooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 based on 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`
    subdomain: SUBDOMAIN,
    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/>

About

NodeJS PassportJS OAuth library for Freshbooks. Based on passport-linkedin

Resources

License

Stars

Watchers

Forks

Packages

No packages published