0.1.0 • Published 3 years ago

passport-daccount v0.1.0

Weekly downloads
33
License
MIT
Repository
github
Last release
3 years ago

passport-daccount

Passport strategy for authenticating with Docomo dAccount using the OAuth 2.0 API.

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

Install

$ npm install passport-daccount

Usage

Configure Strategy

The Docomo dAccount authentication strategy authenticates users using a Docomo 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 Docomo dAccount profile. The verify callback must call cb providing a user to complete authentication.

passport.use(new DAccountStrategy({
    clientID: DACCOUNT_APP_ID,
    clientSecret: DACCOUNT_APP_SECRET,
    callbackURL: "http://localhost:3000/auth/daccount/callback"
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ dAccountId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the 'daccount' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/daccount',
  passport.authenticate('daccount'));

app.get('/auth/daccount/callback',
  passport.authenticate('daccount', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Tests

$ npm install --dev
$ npm test

Credits

License

This project is licensed under the MIT license. See the LICENSE file for more info.

0.1.0

3 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago