passport-typcn-account

0.0.2 • Public • Published

Installation

$ npm install passport-typcn-account

Usage

Configure Strategy

The typcn authentication strategy authenticates users using a typcn 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 client ID, client secret, and callback URL.

passport.use(new TYPStrategy({
    clientID: client_id,
    clientSecret: client_secret
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ typId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

app.get('/auth/typaccount',
  passport.authenticate('typaccount'),
  function(req, res){
    // The request will be redirected to typaccount for authentication, so this
    // function will not be called.
  });

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

Package Sidebar

Install

npm i passport-typcn-account

Weekly Downloads

2

Version

0.0.2

License

none

Last publish

Collaborators

  • typcn