我是Node.js的新手,我正在尝试通过外部CAS服务器实现身份验证系统。我正在使用Passport.js + passport-cas2但是它总是将我重定向到failureRedirect页面,即使CAS正确地验证了我。这是我的代码:
var SocketIOFileUpload = require('socketio-file-upload'),
socketio = require('socket.io'),
express = require('express'),
path = require('path'),
express = require('express'),
passport = require('passport'),
session = require('express-session'),
bodyParser = require('body-parser');
var CasStrategy = require('passport-cas2').Strategy;
var cas = new CasStrategy({
casURL: 'https://my.cas.server'
},
function(username, profile, done) {
console.log("authenticating");
done(null, new User());
});
var app = express()
.use(bodyParser.urlencoded({ extended: true }))
.use(SocketIOFileUpload.router)
.use(passport.initialize());
passport.use(cas);
app.use(session({ secret: 'my secret phrase' }))
.use(passport.session())
.get('/', function(req, res){
res.redirect('/auth/cas');
})
.get('/auth/cas',
passport.authenticate('cas', { failureRedirect: '/error', successRedirect: '/upload' }),
function(req, res) {
// Successful.
res.redirect('/upload');
})
.use('/upload', function(req, res, next){
if (req.user)
return express.static(path.join(__dirname, 'html'));
else
res.redirect('/auth/cas');
})
.get('/error', function(req, res) {
res.send('Error in authentication. Please <a href="/auth/cas">Try Again</a>.');
})
.listen(8080, function () {
console.log('Upload Server started on http://localhost:8080');
});
console.log("authenticating")
根本没有执行!
感谢您的帮助。
答案 0 :(得分:0)
好的,我修好了,我的CAS服务器认证是自签名的,我必须编辑护照-cas2来源才能接受证书。