appirio-tech/passport-topcoder

Name: passport-topcoder

Owner: Topcoder

Description: Passport strategy for Topcoder OAuth provider

Created: 2013-10-17 08:18:47.0

Updated: 2015-05-28 11:14:24.0

Pushed: 2013-10-17 08:30:14.0

Homepage: null

Size: 108

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

passport-topcoder

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

Install
$ npm install passport-topcoder
Usage
Configure Strategy

The Topcoder authentication strategy authenticates users using a Topcoder account and OAuth tokens. The strategy requires a verify callback function, which receives the access token and corresponding refresh token as arguments, along with a profile which contains the authenticated user's Topcoder profile. The verify callback must call done providing a user to complete authentication.

In order to identify your application to TopCoder, specify the client id, client secret, and callback URL within options.

passport.use(new TopcoderStrategy({
        clientID: MY_CLIENT_ID,
        clientSecret: MY_CLIENT_SECRET,
        callbackURL: MY_CALLBACK_URL
    },
    function(accessToken, refreshToken, params, profile, done) {
        var tokenDTO = {
            accessToken: accessToken,
            expirationTime : params.expires_in,
            scope : params.scope.split(" ")
        };
    return done(null, tokenDTO);
    }
));
Authenticate Requests

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

For example, as route middleware in an Express application:

app.get('/auth/topcoder', passport.authenticate('Topcoder', {scope: ["FORUMS_REST", "CONTEST_REST"]}));

app.get('/auth/topcoder/callback', function (req, res, next) {
  passport.authenticate('Topcoder', function (err, token) {
      if (req.query.error) {
          res.render("login", {error: req.query.error});
      } else {
          res.render("login", {token: token});
      }
  })(req, res, next);

});

Examples

For a complete, working example, refer to the signin example.

Tests

Coming…

License

The MIT License


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.