This repo is being depcrecated in favor of passport-hubspot-oauth2 which is being actively maintained and is current with HubSpot's OAuth 2.0 implementation.
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.
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.
};
));
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('/');
});
Based on the great work of Brian Falk (@brainflake) and Jonathan K (@hijonathan)
Code based on passport-facebook by Jared Hanson