0.1.3 • Published 9 years ago

passport-strava-oauth2 v0.1.3

Weekly downloads
205
License
-
Repository
github
Last release
9 years ago

Passport-Strava

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

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

Install

$ npm install passport-strava-oauth2

Usage

Configure Strategy

The Strava authentication strategy authenticates users using an Strava 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.

The client ID and secret are obtained by registering an application at the Login to Strava.

passport.use(new StravaStrategy({
    clientID: STRAVA_CLIENT_ID,
    clientSecret: STRAVA_CLIENT_SECRET,
    callbackURL: "http://127.0.0.1:3000/auth/strava/callback"
  },
  function(accessToken, refreshToken, profile, done) {
    // asynchronous verification, for effect...
    process.nextTick(function () {
  
      // To keep the example simple, the user's Strava profile is returned to
      // represent the logged-in user.  In a typical application, you would want
      // to associate the Strava account with a user record in your database,
      // and return that user instead.
      return done(null, profile);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

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

Examples

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

Credits

Extened from Jared's Amazon example

License

The MIT License

Copyright (c) 2015 Chris Mills [http://www.thefamilymills.co.uk/](http://www.thefamilymills.co.uk/)