passport-oauth2

Build

Onshape authentication strategy for Passport.

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

Install

$ npm install passport-onshape

Usage

Configure Strategy

The Onshape authentication strategy authenticates users using a third-party account and OAuth 2.0 tokens. The provider's client identifer and secret, are specified as options. The strategy requires a verify callback, which receives an access token and profile, and calls done providing a user.

passport.use(new OAuth2Strategy({
    authorizationURL: 'https://oauth.onshape.com/oauth/authorize',
    tokenURL: 'https://oauth.onshape.com/oauth/token',
    clientID: EXAMPLE_CLIENT_ID,
    clientSecret: EXAMPLE_CLIENT_SECRET,
    callbackURL: "http://localhost:3000/auth/example/callback"
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ exampleId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

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

Tests

$ npm install
$ npm test

License

The MIT License

Copyright (c) Onshape Inc <http://onshape.com/>

SEARCH FOR STRATEGIES

0STRATEGIES