Skip to content

OAuth 2.0 authentication strategy for Passport support of the Teamsnap Collection+JSON API

License

Notifications You must be signed in to change notification settings

7elephants/passport-teamsnap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

passport-teamsnap Build Status Dependencies

Passport strategy for authenticating with the Teamsnap API using the OAuth 2.0 protocol.

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

Install

$ npm install passport-teamsnap

Usage

Configure Strategy

The Teamsnap authentication strategy authenticates users using a Teamsnap 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 API version, client ID, client secret, and callback URL. The library defaults to version 3 of Teamsnap's API.

passport.use(new TeamsnapStrategy({
    apiVersion: '3',
    clientID: TEAMSNAP_APPLICATION_ID,
    clientSecret: TEAMSNAP_APPLICATION_SECRET,
    callbackURL: "https://www.example.net/auth/teamsnap/callback"
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ providerId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

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

Tests

To have your tests run against your Teamsnap application, you must supply your Client ID and secret via environment variables.

export TEAMSNAP_CLIENT_ID=<...YOUR APPLICATION ID...>
export TEAMSNAP_SECRET=<...YOUR APPLICATION SECRET...>

mocha --require ../test/bootstrap/node ../test/*.test.js ../test/**/*.test.js

Credits and License

This strategy is based on Jared Hanson's GitHub strategy for passport: Jared Hanson and specifically his work on passport-oauth2

Copyright (c) 2017 Andrew Steiger

About

OAuth 2.0 authentication strategy for Passport support of the Teamsnap Collection+JSON API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published