我正在使用 ADFS 和 passport-saml 在我的sailsjs 应用程序上设置 SSO,当我尝试登录它时抛出:TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Location"]
代替重定向到我们的 adfs(IDp)
我尝试了两个过程,一个是passport-saml
(参考 - http://www.passportjs.org/packages/passport-saml/),另一个是passport-wsdef-saml2
(参考 - https://github.com/auth0/passport-wsfed-saml2)但是两种实现都出现相同的错误。我已经通过这个 url - SAML/ADFS node.js 实施指南?但在代码中没有发现任何遗漏。我将我的护照-saml 实施代码放在这里。
passport.js -
passport.use(new SamlStrategy({
entryPoint: 'https://myadfs.com/adfs/ls',
issuer: 'app-identity',
callbackUrl: 'https://my-app.com/login/callback',
cert: fs.readFileSync(__dirname + '/ssl/sign.crt', 'utf-8'),
authnContext:
'http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/password',
identifierFormat: null
},
function(profile, done) {
console.log("data : ", profile );
var data = {
email: profile['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'],
givenname: profile['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname'],
surname: profile['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname']
}
done(null, data);
}));
route.js -
'GET /signin': 'AuthController.dologin',
'post /login/callback': 'AuthController.callback',
'/logout': 'AuthController.logout',`
AuthController.js -
`dologin: function(req, res) {
passport.authenticate('saml', (req, res) => {
res.redirect('/');
})(req, res);
},
callback: [passport.authenticate('saml', {failureRedirect: '/',failureFlash: true}), function(req, res) {
console.log(req.body);
console.log(req.user);
if (!req.user) {
throw Error('User not authenticated.');
}
res.redirect('/');
}
],
logout: function(req, res) {
req.logout();
res.redirect('/login');
}
http.js -
passportInit: require('passport').initialize(),
passportSession: require('passport').session(),
order: [
'cookieParser',
'session',
'passportInit',
'passportSession',
'bodyParser',
'compress',
'poweredBy',
'router',
'www',
'favicon',
],
请帮帮我,我什至无法找到问题所在。根据教程和发现,似乎没有什么不正确的,但它仍然没有重定向到 ADFS 身份提供程序服务器,并引发以下错误 -
0|app | TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Location"]
0|app | at ServerResponse.setHeader (_http_outgoing.js:473:3)
0|app | at Strategy.strategy.redirect (app/node_modules/passport/lib/middleware/authenticate.js:323:13)
0|app | at redirectIfSuccess (app/node_modules/passport-saml/lib/passport-saml/strategy.js:77:12)
0|app | at DeflateRaw.requestToUrlHelper [as cb] (app/node_modules/passport-saml/lib/passport-saml/saml.js:361:5)
0|app | at DeflateRaw.zlibBufferOnEnd (zlib.js:131:10)
0|app | at DeflateRaw.emit (events.js:203:15)
0|app | at endReadableNT (_stream_readable.js:1129:12)
0|app | at process._tickCallback (internal/process/next_tick.js:63:19)
请帮助我该怎么做,上面代码中的问题可能出在哪里。
先感谢您。