简体   繁体   English

Passport-cas2始终重定向到failureRedirect

[英]Passport-cas2 always redirecting to failureRedirect

I'm quite new to Node.js and I'm trying to implement an authentication system through an external CAS server. 我对Node.js还是很陌生,我正在尝试通过外部CAS服务器实现身份验证系统。 I'm using Passport.js + passport-cas2 but it's always redirecting me to the failureRedirect page even though the CAS correctly authenticated me. 我正在使用Passport.js + Passport-cas2,但是即使CAS正确地对我进行了身份验证,它也始终将我重定向到failureRedirect页面。 Here is my code: 这是我的代码:

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');
    });

The console.log("authenticating") isn't even executed at all! console.log("authenticating")甚至根本没有执行!

Thanks for your help. 谢谢你的帮助。

好的,我已修复它,我的CAS服务器证书是自签名的,我必须编辑passport-cas2源才能使其接受证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM