Skip to content

Punwave authentication strategy for Passport and Node.js.

License

Notifications You must be signed in to change notification settings

punwave/passport-punwave

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

passport-punwave

NPM version Build Status Coverage Status

Passport strategy for authenticating with Punwave using the OAuth 2.0 API.

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

Install

$ npm install passport-punwave

Usage

Configure Strategy

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

passport.use(new PunwaveStrategy({
    clientID: PUNWAVE_APP_ID,
    clientSecret: PUNWAVE_APP_SECRET,
    callbackURL: "http://localhost:3000/auth/punwave/callback"
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ punwaveId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

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

License

MIT

About

Punwave authentication strategy for Passport and Node.js.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages