title: Possible to log in specific user with Passport Strava strategy without log in screen?
body: <p>I want to have an online map which publicly loads and shows all my activities from my Strava account.</p>
  <p>I have found a web app on GitHub which does what I want but the user has to log in with the Strava log in screen before he than can see his own activities: <a href="https://github.com/nsynes/ActivityMap" rel="nofollow noreferrer">https://github.com/nsynes/ActivityMap</a></p>
  <p>It seems it uses Passport Strava to authenticate with Strava: <a href="https://www.passportjs.org/packages/passport-strava-oauth2/" rel="nofollow noreferrer">https://www.passportjs.org/packages/passport-strava-oauth2/</a></p>
  <p>Is it possible to adjust the script so it always logs in automatically my account and than shows my activities publicly to everyone who visits the map?</p>
  <p>The full script is here: <a href="https://github.com/nsynes/ActivityMap/blob/master/activity-map-app.js" rel="nofollow noreferrer">https://github.com/nsynes/ActivityMap/blob/master/activity-map-app.js</a></p>
  <p>My STRAVA_CLIENT_ID and STRAVA_CLIENT_SECRET are from my Strava account and saved in a .env file.</p>
  <pre><code>const express = require('express')
  const passport = require('passport')
  const util = require('util')
  const StravaStrategy = require('passport-strava-oauth2').Strategy
  const dotenv = require('dotenv');
  const path = require('path');
  const cookieParser = require('cookie-parser')
  const bodyParser = require('body-parser');
  const session = require('express-session');
  var strava = require('strava-v3');
  const decode = require('geojson-polyline').decode
  const geodist = require('geodist');
  
  dotenv.config();
  
  const port = process.env.PORT || 3000
  const app = express();
  
  
  // configure Express
  //app.use(express.logger());
  app.use(cookieParser());
  app.use(bodyParser.urlencoded({ extended: false }));
  //app.use(express.methodOverride());
  app.use(session({
      secret: 'monkey tennis',
      resave: true,
      saveUninitialized: true,
      maxAge: 1800 * 1000
  }));
  app.use(passport.initialize());
  app.use(passport.session());
  app.use('/css', express.static(path.join(__dirname, 'css')));
  app.use('/fontawesome', express.static(path.join(__dirname, 'fontawesome')));
  app.use('/js', express.static(path.join(__dirname, 'js')));
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  
  // Passport session setup.
  passport.serializeUser(function(user, done) { done(null, user) });
  passport.deserializeUser(function(obj, done) {done(null, obj) });
  
  passport.use(new StravaStrategy({
      clientID: process.env.STRAVA_CLIENT_ID,
      clientSecret: process.env.STRAVA_CLIENT_SECRET,
      callbackURL: &quot;/auth/strava/callback&quot;
    },
    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);
      });
    }
  ));
  
  app.get('/', ensureAuthenticated, function(req, res){
      pagePath = path.join(__dirname, '/index.html');
      res.sendFile(pagePath);
  });
  
  app.get('/userPhoto', ensureAuthenticated, function(req, res){
      if ( req.user ) {
          res.json({ 'photo': req.user.photos[req.user.photos.length-1].value });
      } else {
          res.sendStatus(404);
      }
  });
  
  // Use passport.authenticate() as route middleware to authenticate the
  // request.  Redirect user to strava, then strava will redirect user back to
  // this application at /auth/strava/callback
  app.get('/auth/strava',
    passport.authenticate('strava', { scope: ['activity:read'], approval_prompt: ['force'] }),
    function(req, res){
      // The request will be redirected to Strava for authentication, so this
      // function will not be called.
    });
  
  // GET /auth/strava/callback
  //   Use passport.authenticate() as route middleware to authenticate the
  //   request.  If authentication fails, the user will be redirected back to the
  //   login page.  Otherwise, the primary route function function will be called,
  //   which, in this example, will redirect the user to the home page.
  app.get('/auth/strava/callback',
    passport.authenticate('strava', { failureRedirect: '/login' }),
    function(req, res) {
      res.redirect('/');
    });
  
  app.get('/logout', function(req, res){
    req.logout();
    res.cookie(&quot;connect.sid&quot;, &quot;&quot;, { expires: new Date() });
    res.render('login', { user: req.user });
  });
  
  app.get('/login', function(req, res){
      res.render('login', { user: req.user });
    });
  </code></pre>