Passport-BaseCRM

Build Status Coverage Status Code Climate Dependency Status

Passport strategy for authenticating with BaseCRM using the OAuth 2.0 API. Visit Base Developers to get familiar with their API. You need to register your application with Base to be able to access their API.

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

Install

$ npm install passport-basecrm

Usage

Configure Strategy

In order to identify your application to BaseCRM, specify the client_id, client_secret and redirect_uri (callback that you provided when registering the application) within the options. The client_id and client_secret are obtained by registering your application in your BaseCRM account under Settings -> OAuth -> Developer Apps tab.

passport.use(new BaseCRMStrategy({
    clientID: BaseCRM_CLIENT_ID,
    clientSecret: BaseCRM_CLIENT_SECRET,
    callbackURL: "http://127.0.0.1:3000/auth/basecrm/callback"
    scope: ['read', 'profile', 'write', 'sync']
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ basecrmId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

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

Examples

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

Tests

$ npm install --dev
$ make test

Credits

License

The MIT License

Copyright (c) 2015 Reydel Leon https://www.linkedin.com/in/reydelleon

SEARCH FOR STRATEGIES

0STRATEGIES