简体   繁体   中英

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. I'm using Passport.js + passport-cas2 but it's always redirecting me to the failureRedirect page even though the CAS correctly authenticated me. 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!

Thanks for your help.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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