Neurotic and Probably Misinformed

    passport-hubspot

    0.1.0 • Public • Published

    Passport-Hubspot

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

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

    Usage

    Configure Strategy

    The HubSpot authentication strategy authenticates users using a HubSpot account and OAuth 2.0 tokens.

    NOTE: Unlike normal OAuth 2.0 flows, HubSpot immediately returns an access token instead of an authorization code. Therefore, unlike other passport strategies, this strategy does not actually call the verify callback.

    passport.use(new HubSpotStrategy({
        clientID: HUBSPOT_APP_ID,
        clientSecret: HUBSPOT_APP_SECRET,
        callbackURL: "http://localhost:3000/auth/hubspot/callback"
      }, function() {
        // Useless verify callback.
      };
    ));
    

    Authenticate Requests

    Use passport.authenticate(), specifying the 'hubspot' strategy, to authenticate requests. You'll also need to provide a portalId and any scopes you'll need access to.

    For example, as route middleware in an Express application:

    app.get('/auth/hubspot', passport.authenticate('hubspot', {
        portalId: 62515,
        scope: ['offline', 'contacts-ro', 'contacts-rw']
      })
    );
    
    app.get('/auth/hubspot/callback', function(req, res) {
        // Access tokens are returned immediately as params, which you can then store somehow.
        console.log(req.params);
    
        // Redirect to home.
        res.redirect('/');
    });
    

    Credits

    Based on the great work of Brian Falk (@brainflake)

    Code based on passport-facebook by Jared Hanson

    License

    The MIT License

    Install

    npm i passport-hubspot

    DownloadsWeekly Downloads

    44

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • brainflake