我正在尝试配置passport-civic
,这是我的代码:
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;
到达/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)
您可以在此处找到passport-civic
文档:https://www.npmjs.com/package/passport-civic
以下是passport
个文档:http://www.passportjs.org/docs/
更新
在其信息中心中创建civic
应用时,他们要求提供whitelist
域-可能是因为我在本地主机上而不是我列入白名单的域(omniatm.eamondev.com
)上的错误? ?
更新
我在域ominatm.eamondev.com
上进行了尝试,似乎whitelist
并不是问题,因为我仍然遇到错误。