@matters/passport-likecoin
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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('/');
  });

License

The MIT License

Package Sidebar

Install

npm i @matters/passport-likecoin

Weekly Downloads

25

Version

1.0.0

License

MIT

Unpacked Size

5.68 kB

Total Files

6

Last publish

Collaborators

  • matters_npm
  • devformatters
  • robermac
  • guoliu11