Strava authentication strategy for Passport and Node.js.
As base I used Passport-Facebook. I just made a few changes to display the data that comes from Strava.
This lib aims to make it easier the Strava authentication with Nodejs apps. By plugging into Passport, Strava authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
$ npm i @riderize/passport-strava-oauth2
Strava uses the OAuth2 strategy in order to authenticate the users. This strategy requires a callback, that receives these credentials and calls done
returning the data of the user logged in as well as options to specify the Client ID
, Client Secret
and Callback URL
.
In order to obtain a Client ID and Client Secret first you have to register an app at Strava.
Basic config:
const StravaStrategy = require('@riderize/passport-strava-oauth2').Strategy;
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) {
User.findOrCreate({ stravaId: profile.id }, function (err, user) {
return done(err, user);
});
}
));
With Typescript:
import strategy from '@riderize/passport-strava-oauth2';
const StravaStrategy = strategy.Strategy;
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) {
User.findOrCreate({ stravaId: profile.id }, function (err, user) {
return done(err, user);
});
}
));
- The types of this lib are now on @types/riderize__passport-strava-oauth2
- To Jared Hanson for making Passport possible.