Я пытаюсь использовать passport-saml для аутентификации, но после авторизации через ошибку Error: SAML provider returned Requester error: An error occurred.
Когда я нажимаю на кнопку входа, он перенаправляет меня на страницу входа в систему IDP, где я предоставляю имя пользователя и пароль, а затем перенаправляет на мою функцию / login / callback, где происходит сбой.
app.js
const express = require('express');
const http = require('http');
const path = require('path');
const passport = require('passport');
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const session = require('express-session');
const errorhandler = require('errorhandler');
var env = process.env.NODE_ENV || 'development';
const config = require('./config/config')[env];
console.log('Using configuration', config);
require('./config/passport')(passport, config);
var app = express();
app.set('port', config.app.port);
app.set('views', __dirname + '/app/views');
app.set('view engine', 'jade');
app.use(morgan('combined'));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(session(
{
resave: true,
saveUninitialized: true,
secret: 'this shit hits'
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));
require('./config/routes')(app, config, passport);
app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});
routes.js
module.exports = function (app, config, passport) {
app.get('/', function (req, res) {
if (req.isAuthenticated()) {
res.render('home',
{
user: req.user
});
} else {
res.render('home',
{
user: null
});
}
});
app.get('/login',
passport.authenticate(config.passport.strategy,
{
successRedirect: '/',
failureRedirect: '/login'
})
);
app.post(config.passport.saml.path,
passport.authenticate(config.passport.strategy,
{
failureRedirect: '/',
failureFlash: true
}),
function (req, res) {
res.redirect('/');
}
);
app.get('/signup', function (req, res) {
res.render('signup');
});
app.get('/profile', function (req, res) {
if (req.isAuthenticated()) {
res.render('profile',
{
user: req.user
});
} else {
res.redirect('/login');
}
});
app.get('/logout', function (req, res) {
req.logout();
// TODO: invalidate session on IP
res.redirect('/');
});
};
passport.js
const SamlStrategy = require('passport-saml').Strategy;
module.exports = function (passport, config) {
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (user, done) {
done(null, user);
});
passport.use(new SamlStrategy(
{
path: config.passport.saml.path,
entryPoint: config.passport.saml.entryPoint,
issuer: config.passport.saml.issuer,
cert: config.passport.saml.cert
},
function (profile, done) {
return done(null,
{
id: profile.uid,
email: profile.email,
displayName: profile.cn,
firstName: profile.givenName,
lastName: profile.sn
});
})
);
};
config.js
module.exports = {
development: {
app: {
name: 'Passport SAML strategy example',
port: process.env.PORT || 3000
},
passport: {
strategy: 'saml',
saml: {
path: process.env.SAML_PATH || '/login/callback',
entryPoint: process.env.SAML_ENTRY_POINT || 'https://idp.example.io/idp/profile/SAML2/Redirect/SSO',
issuer: 'https://sp.example.io/shibboleth',
cert: process.env.SAML_CERT || '/etc/ssl/certs/ssl-sp.crt'
}
}
}
};
Это ошибка, которую я получил в консоли и браузере
Error: SAML provider returned Requester error: An error occurred.
at /root/passport-saml-ex1/node_modules/passport-saml/lib/passport-saml/saml.js:677:31
at _fulfilled (/root/passport-saml-ex1/node_modules/q/q.js:854:54)
at /root/passport-saml-ex1/node_modules/q/q.js:883:30
at Promise.promise.promiseDispatch (/root/passport-saml-ex1/node_modules/q/q.js:816:13)
at /root/passport-saml-ex1/node_modules/q/q.js:570:49
at runSingle (/root/passport-saml-ex1/node_modules/q/q.js:137:13)
at flush (/root/passport-saml-ex1/node_modules/q/q.js:125:13)
at process._tickCallback (internal/process/next_tick.js:61:11)
и это ответ, который я получил
<?xml version="1.0" encoding="UTF-8"?>
<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" Destination="http://sp.example.io:3000/login/callback" ID="_a41e13c5b43026d0b854985b77699814" InResponseTo="_0d7bb680083c3aa20048" IssueInstant="2019-01-08T20:26:24.715Z" Version="2.0">
<saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">https://idp.example.io/idp/shibboleth</saml2:Issuer>
<saml2p:Status>
<saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Requester">
<saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:InvalidNameIDPolicy" />
</saml2p:StatusCode>
<saml2p:StatusMessage>An error occurred.</saml2p:StatusMessage>
</saml2p:Status>
</saml2p:Response>