gpt4 book ai didi

node.js - Passport-saml 实现

转载 作者:太空宇宙 更新时间:2023-11-03 23:40:52 25 4
gpt4 key购买 nike

我正在尝试让 Passport 与任何策略配合使用,但最终我希望让它与 SAML 实现配合使用。现在看来总是一调用策略就失败。我想知道我的服务器处理程序链是否设置错误?

`

'use strict';
// ---------------------------------- BEGIN MODULE SCOPE VARIABLES ----------------------------------
var
http = require('http'),
express = require('express'),
session = require('express-session'),
path = require("path"),
samlStrategy = require('passport-saml').Strategy,
passport = require('passport'),
//flash = require('connect-flash'),
morgan = require('morgan'),
app = express(),
server = http.createServer(app);

// ---------------------------------- END MODULE SCOPE VARIABLES ------------------------------------

// ---------------------------------- BEGIN SERVER CONFIGURATION ------------------------------------

app.configure(function () {
app.use(app.router);
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({ secret: 'keyboard cat' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.methodOverride());
app.use(morgan('dev')); // log every request to the console
app.use(express.static(__dirname + '/public'));
});

passport.use('saml', new samlStrategy({

path: '/login/callback',
entryPoint: 'https://openidp.feide.no/simplesaml/module.php/openidProvider/user.php/sso',
issuer: 'passport-saml',
protocol: 'http://',
cert: 'MIICizCCAfQCCQCY8tKaMc0BMjANBgkqhkiG9w0BAQUFADCBiTELMAkGA1UEBhMCTk8xEjAQBgNVBAgTCVRyb25kaGVpbTEQMA4GA1UEChMHVU5JTkVUVDEOMAwGA1UECxMFRmVpZGUxGTAXBgNVBAMTEG9wZW5pZHAuZmVpZGUubm8xKTAnBgkqhkiG9w0BCQEWGmFuZHJlYXMuc29sYmVyZ0B1bmluZXR0Lm5vMB4XDTA4MDUwODA5MjI0OFoXDTM1MDkyMzA5MjI0OFowgYkxCzAJBgNVBAYTAk5PMRIwEAYDVQQIEwlUcm9uZGhlaW0xEDAOBgNVBAoTB1VOSU5FVFQxDjAMBgNVBAsTBUZlaWRlMRkwFwYDVQQDExBvcGVuaWRwLmZlaWRlLm5vMSkwJwYJKoZIhvcNAQkBFhphbmRyZWFzLnNvbGJlcmdAdW5pbmV0dC5ubzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAt8jLoqI1VTlxAZ2axiDIThWcAOXdu8KkVUWaN/SooO9O0QQ7KRUjSGKN9JK65AFRDXQkWPAu4HlnO4noYlFSLnYyDxI66LCr71x4lgFJjqLeAvB/GqBqFfIZ3YK/NrhnUqFwZu63nLrZjcUZxNaPjOOSRSDaXpv1kb5k3jOiSGECAwEAATANBgkqhkiG9w0BAQUFAAOBgQBQYj4cAafWaYfjBU2zi1ElwStIaJ5nyp/s/8B8SAPK2T79McMyccP3wSW13LHkmM1jwKe3ACFXBvqGQN0IbcH49hu0FKhYFM/GPDJcIHFBsiyMBXChpye9vBaTNEBCtU3KjjyG0hRT2mAQ9h+bkPmOvlEo/aH0xR68Z9hw4PF13w=='
//privateCert: fs.readFileSync('./cert.pem', 'utf-8')
},
function(profile, done) {
console.log("Auth with", profile);
if (!profile.email) {
return done(new Error("No email found"), null);
}
// asynchronous verification, for effect...
process.nextTick(function () {
findByEmail(profile.email, function(err, user) {
if (err) {
return done(err);
}
if (!user) {
// "Auto-registration"
users.push(profile);
return done(null, profile);
}
return done(null, user);
})
});
}
));

app.get('/XA', passport.authenticate('local-login', {
failureRedirect: '/404.html', // redirect
failureFlash: false // allow flash messages
})
);

app.get('/XA/callback',
passport.authenticate('saml', {
successRedirect : '/index.html',
failureRedirect : '/failure'
}));`

最佳答案

从上面我无法准确判断您的失败是什么,但您可能想要尝试的一件事是将 samlFallback: login-request 参数传递给您的身份验证调用。

如果没有这个,我不相信该库会将登录重定向到您的 SAML 提供商的入口点,因此对该路由的调用只会显示身份验证失败。

--

更新:

从版本 0.4.0 开始,我刚刚将 samlFallback: login-request 设置为默认值,因此您应该能够仅更新您的 Passport-saml 版本并获得正确的行为。

关于node.js - Passport-saml 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24092211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com