passport/passport-civic: Error exchanging code for data: [Bad Request] missing authToken











up vote
0
down vote

favorite












I am trying to configure passport-civic, here is my code:



var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var passport = require('passport');
var CivicStrategy = require('passport-civic').Strategy;

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var loginRouter = require('./routes/login');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require('express-session')({ secret: 'xxx', resave: true, saveUninitialized: true }));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/login', loginRouter);

passport.use(new CivicStrategy({
appId: 'xxx',
prvKey: 'xxx',
appSecret: 'xxx'
},
function(profile, done) {
User.findOrCreate({ civicId: profile.userId }, function (err, user) {
return done(err, user);
});
}
));

passport.serializeUser(function(user, done) {
done(null, user.id);
});

passport.deserializeUser(function(id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
});

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

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

// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

module.exports = app;


The error when I reach /auth/civic:



Error: Error exchanging code for data: [Bad Request] missing authToken
at Object._callee$ (/Volumes/EamonWD/omniatm/omni-atm/node_modules/passport-civic/node_modules/civic-sip-api/dist/index.js:107:26)
at tryCatch (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as throw] (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:114:21)
at step (/Volumes/EamonWD/omniatm/omni-atm/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /Volumes/EamonWD/omniatm/omni-atm/node_modules/babel-runtime/helpers/asyncToGenerator.js:30:13
at process._tickCallback (internal/process/next_tick.js:68:7)


You can find the passport-civic documentation here: https://www.npmjs.com/package/passport-civic



Here is passport documentation: http://www.passportjs.org/docs/



UPDATE



When creating the civic app in their dashboard, they asked for whitelist domains - could this error be because I am trying it on localhost and not the domain I whitelisted (omniatm.eamondev.com)?



UPDATE
I tried it on my domain ominatm.eamondev.com and it seems like the whitelist isn't the problem as I still get the error.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am trying to configure passport-civic, here is my code:



    var createError = require('http-errors');
    var express = require('express');
    var path = require('path');
    var cookieParser = require('cookie-parser');
    var logger = require('morgan');
    var passport = require('passport');
    var CivicStrategy = require('passport-civic').Strategy;

    var indexRouter = require('./routes/index');
    var usersRouter = require('./routes/users');
    var loginRouter = require('./routes/login');

    var app = express();

    // view engine setup
    app.set('views', path.join(__dirname, 'views'));
    app.set('view engine', 'jade');

    app.use(logger('dev'));
    app.use(express.json());
    app.use(express.urlencoded({ extended: false }));
    app.use(cookieParser());
    app.use(require('express-session')({ secret: 'xxx', resave: true, saveUninitialized: true }));
    app.use(passport.initialize());
    app.use(passport.session());
    app.use(express.static(path.join(__dirname, 'public')));

    app.use('/', indexRouter);
    app.use('/users', usersRouter);
    app.use('/login', loginRouter);

    passport.use(new CivicStrategy({
    appId: 'xxx',
    prvKey: 'xxx',
    appSecret: 'xxx'
    },
    function(profile, done) {
    User.findOrCreate({ civicId: profile.userId }, function (err, user) {
    return done(err, user);
    });
    }
    ));

    passport.serializeUser(function(user, done) {
    done(null, user.id);
    });

    passport.deserializeUser(function(id, done) {
    User.findById(id, function (err, user) {
    done(err, user);
    });
    });

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

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

    // catch 404 and forward to error handler
    app.use(function(req, res, next) {
    next(createError(404));
    });

    // error handler
    app.use(function(err, req, res, next) {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};

    // render the error page
    res.status(err.status || 500);
    res.render('error');
    });

    module.exports = app;


    The error when I reach /auth/civic:



    Error: Error exchanging code for data: [Bad Request] missing authToken
    at Object._callee$ (/Volumes/EamonWD/omniatm/omni-atm/node_modules/passport-civic/node_modules/civic-sip-api/dist/index.js:107:26)
    at tryCatch (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as throw] (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/Volumes/EamonWD/omniatm/omni-atm/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /Volumes/EamonWD/omniatm/omni-atm/node_modules/babel-runtime/helpers/asyncToGenerator.js:30:13
    at process._tickCallback (internal/process/next_tick.js:68:7)


    You can find the passport-civic documentation here: https://www.npmjs.com/package/passport-civic



    Here is passport documentation: http://www.passportjs.org/docs/



    UPDATE



    When creating the civic app in their dashboard, they asked for whitelist domains - could this error be because I am trying it on localhost and not the domain I whitelisted (omniatm.eamondev.com)?



    UPDATE
    I tried it on my domain ominatm.eamondev.com and it seems like the whitelist isn't the problem as I still get the error.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to configure passport-civic, here is my code:



      var createError = require('http-errors');
      var express = require('express');
      var path = require('path');
      var cookieParser = require('cookie-parser');
      var logger = require('morgan');
      var passport = require('passport');
      var CivicStrategy = require('passport-civic').Strategy;

      var indexRouter = require('./routes/index');
      var usersRouter = require('./routes/users');
      var loginRouter = require('./routes/login');

      var app = express();

      // view engine setup
      app.set('views', path.join(__dirname, 'views'));
      app.set('view engine', 'jade');

      app.use(logger('dev'));
      app.use(express.json());
      app.use(express.urlencoded({ extended: false }));
      app.use(cookieParser());
      app.use(require('express-session')({ secret: 'xxx', resave: true, saveUninitialized: true }));
      app.use(passport.initialize());
      app.use(passport.session());
      app.use(express.static(path.join(__dirname, 'public')));

      app.use('/', indexRouter);
      app.use('/users', usersRouter);
      app.use('/login', loginRouter);

      passport.use(new CivicStrategy({
      appId: 'xxx',
      prvKey: 'xxx',
      appSecret: 'xxx'
      },
      function(profile, done) {
      User.findOrCreate({ civicId: profile.userId }, function (err, user) {
      return done(err, user);
      });
      }
      ));

      passport.serializeUser(function(user, done) {
      done(null, user.id);
      });

      passport.deserializeUser(function(id, done) {
      User.findById(id, function (err, user) {
      done(err, user);
      });
      });

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

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

      // catch 404 and forward to error handler
      app.use(function(req, res, next) {
      next(createError(404));
      });

      // error handler
      app.use(function(err, req, res, next) {
      // set locals, only providing error in development
      res.locals.message = err.message;
      res.locals.error = req.app.get('env') === 'development' ? err : {};

      // render the error page
      res.status(err.status || 500);
      res.render('error');
      });

      module.exports = app;


      The error when I reach /auth/civic:



      Error: Error exchanging code for data: [Bad Request] missing authToken
      at Object._callee$ (/Volumes/EamonWD/omniatm/omni-atm/node_modules/passport-civic/node_modules/civic-sip-api/dist/index.js:107:26)
      at tryCatch (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as throw] (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:114:21)
      at step (/Volumes/EamonWD/omniatm/omni-atm/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
      at /Volumes/EamonWD/omniatm/omni-atm/node_modules/babel-runtime/helpers/asyncToGenerator.js:30:13
      at process._tickCallback (internal/process/next_tick.js:68:7)


      You can find the passport-civic documentation here: https://www.npmjs.com/package/passport-civic



      Here is passport documentation: http://www.passportjs.org/docs/



      UPDATE



      When creating the civic app in their dashboard, they asked for whitelist domains - could this error be because I am trying it on localhost and not the domain I whitelisted (omniatm.eamondev.com)?



      UPDATE
      I tried it on my domain ominatm.eamondev.com and it seems like the whitelist isn't the problem as I still get the error.










      share|improve this question















      I am trying to configure passport-civic, here is my code:



      var createError = require('http-errors');
      var express = require('express');
      var path = require('path');
      var cookieParser = require('cookie-parser');
      var logger = require('morgan');
      var passport = require('passport');
      var CivicStrategy = require('passport-civic').Strategy;

      var indexRouter = require('./routes/index');
      var usersRouter = require('./routes/users');
      var loginRouter = require('./routes/login');

      var app = express();

      // view engine setup
      app.set('views', path.join(__dirname, 'views'));
      app.set('view engine', 'jade');

      app.use(logger('dev'));
      app.use(express.json());
      app.use(express.urlencoded({ extended: false }));
      app.use(cookieParser());
      app.use(require('express-session')({ secret: 'xxx', resave: true, saveUninitialized: true }));
      app.use(passport.initialize());
      app.use(passport.session());
      app.use(express.static(path.join(__dirname, 'public')));

      app.use('/', indexRouter);
      app.use('/users', usersRouter);
      app.use('/login', loginRouter);

      passport.use(new CivicStrategy({
      appId: 'xxx',
      prvKey: 'xxx',
      appSecret: 'xxx'
      },
      function(profile, done) {
      User.findOrCreate({ civicId: profile.userId }, function (err, user) {
      return done(err, user);
      });
      }
      ));

      passport.serializeUser(function(user, done) {
      done(null, user.id);
      });

      passport.deserializeUser(function(id, done) {
      User.findById(id, function (err, user) {
      done(err, user);
      });
      });

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

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

      // catch 404 and forward to error handler
      app.use(function(req, res, next) {
      next(createError(404));
      });

      // error handler
      app.use(function(err, req, res, next) {
      // set locals, only providing error in development
      res.locals.message = err.message;
      res.locals.error = req.app.get('env') === 'development' ? err : {};

      // render the error page
      res.status(err.status || 500);
      res.render('error');
      });

      module.exports = app;


      The error when I reach /auth/civic:



      Error: Error exchanging code for data: [Bad Request] missing authToken
      at Object._callee$ (/Volumes/EamonWD/omniatm/omni-atm/node_modules/passport-civic/node_modules/civic-sip-api/dist/index.js:107:26)
      at tryCatch (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as throw] (/Volumes/EamonWD/omniatm/omni-atm/node_modules/regenerator-runtime/runtime.js:114:21)
      at step (/Volumes/EamonWD/omniatm/omni-atm/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
      at /Volumes/EamonWD/omniatm/omni-atm/node_modules/babel-runtime/helpers/asyncToGenerator.js:30:13
      at process._tickCallback (internal/process/next_tick.js:68:7)


      You can find the passport-civic documentation here: https://www.npmjs.com/package/passport-civic



      Here is passport documentation: http://www.passportjs.org/docs/



      UPDATE



      When creating the civic app in their dashboard, they asked for whitelist domains - could this error be because I am trying it on localhost and not the domain I whitelisted (omniatm.eamondev.com)?



      UPDATE
      I tried it on my domain ominatm.eamondev.com and it seems like the whitelist isn't the problem as I still get the error.







      javascript node.js express authentication passport.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 at 13:29

























      asked Nov 12 at 23:13









      ewizard

      1,06122467




      1,06122467





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271454%2fpassport-passport-civic-error-exchanging-code-for-data-bad-request-missing-a%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271454%2fpassport-passport-civic-error-exchanging-code-for-data-bad-request-missing-a%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?