passport-hitsend-dev
v1.0.1
Published
OAuth2 authentication strategy for HitSend
Downloads
6
Maintainers
Readme
Passport-HitSend
Passport strategy for authenticating with HitSend using the OAuth 2.0 API.
This module lets you authenticate using HitSend in your Node.js applications. By plugging into Passport, HitSend authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
Usage
Configure Strategy
The HitSend authentication strategy authenticates users using a HitSend
account and OAuth 2.0 tokens. The strategy requires a verify
callback, which
accepts these credentials and calls done
providing a user, as well as
options
specifying a app ID, app secret, and callback URL.
const passport = require('passport');
const HitSendStrategy = require('passport-hitsend').Stratey;
passport.use(new HitSendStrategy({
clientID: HitSend_APP_ID,
callbackURL: "http://localhost:3000/auth/HitSend/callback"
}, function (accessToken, refreshToken, profile, done) {
User.findOrCreate({ HitSendId: HitSend.id }, function(err, user) {
return done(err, user);
};
})
);
Authenticate Requests
Use passport.authenticate()
, specifying the 'HitSend'
strategy, to
authenticate requests.
For example, as route middleware in an Express application:
app.get('/auth/HitSend', passport.authenticate('HitSendStrategy'));
app.get('/auth/HitSend/callback',
passport.authenticate('HitSendStrategy', { failureRedirect: '/login' }),
function(req, res) {
// Successul authentication, redirect home.
res.redirect('/');
});
Credits
Created by Gary Dickerson
Code based on passport-mailchimp by Brian Falk