@matters/passport-likecoin
v1.0.0
Published
LikeCoin (like.co) authentication strategy for Passport and Node.js.
Downloads
76
Readme
passport-likecoin
Passport strategy for authenticating with LikeCoin using the OAuth 2.0 API.
Install
$ npm install @matters/passport-likecoin
Usage
Configure Strategy
The LikeCoin authentication strategy authenticates users using a LikeCoin
account and OAuth 2.0 tokens. The app ID and secret obtained when creating an
application are supplied as options when creating the strategy. The strategy
also requires a verify
callback, which receives the access token and optional
refresh token, as well as profile
which contains the authenticated user's
LikeCoin profile. The verify
callback must call cb
providing a user to
complete authentication.
passport.use(new LikeCoinStrategy({
clientID: LIKECOIN_CLIENT_ID,
clientSecret: LIKECOIN_CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/likecoin/callback"
},
function(accessToken, refreshToken, params, profile, cb) {c
const likerId = params.user;
User.findOrCreate({ likerId }, function (err, user) {
return cb(err, user);
});
}
));
Authenticate Requests
Use passport.authenticate()
, specifying the 'likecoin'
strategy, to
authenticate requests.
For example, as route middleware in an Express application:
app.get('/auth/likecoin',
passport.authenticate('likecoin'));
app.get('/auth/likecoin/callback',
passport.authenticate('likecoin', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});