Node.js应用程序与WSO2身份服务器集成以进行单点登录

时间:2018-05-24 22:45:04

标签: node.js express wso2 single-sign-on

我正在尝试使用WSO2身份服务器为Node.js应用程序实现单点登录服务。我是SSO领域的新手。

我已在本地部署了WSO2身份服务器。

我正在使用这个简单的节点应用程序作为服务提供者。

var express = require("express");
var passport = require("passport");
var SamlStrategy = require('passport-saml').Strategy;
var bodyParser = require("body-parser");
var session = require("express-session");
var app = express();
app.use(bodyParser.urlencoded({
  extended: true
}));
app.use(session({ secret: 'this shit hits'}));
app.use(passport.initialize());
app.use(passport.session());

var redirectLogin = function (req,res,next) {
   if (!req.isAuthenticated()) {
       res.redirect("/myapp/login");
   }
   next();
}
passport.serializeUser(function(user, done) {
     done(null, user);
});

passport.deserializeUser(function(user, done) {

  done(null, user);
});

passport.use(new SamlStrategy({
    entryPoint: 'https://localhost:9443/samlsso',
    issuer: 'MyAppExpress'
  },
  function(profile, done) {
    var myUser = {
      email : profile.nameID
    }
    done(null, myUser);
  }));

app.get('/myapp/login',
  passport.authenticate('saml', {
    successRedirect: "/myapp",
    failureRedirect: "/myapp/login",
  }));

app.post('/myapp/saml', passport.authenticate('saml', {
    failureRedirect: "/myapp/login",
    failureFlash: true
  })
  ,
  function(req, res) {
    res.redirect("/myapp");
  }
);
app.get("/myapp",redirectLogin, function(req, res) {
    res.send("you're authenticated !!!! "+ JSON.stringify(req.user));
});

app.listen(process.env.PORT || 1234);

WSO2身份服务器上的服务提供商配置包括: enter image description here

enter image description here

我遵循了此链接上给出的指导原则。 SAML Authentication with WSO2 / LDAP / PASSPORT / EXPRESS

目前,我面临以下问题:

  • ALERT:无效的断言消费者网址值' http://localhost:1234/saml/consume'在来自发行人的MyAppExpress'的AuthnRequest消息中。可能是欺骗攻击的企图。当我尝试使用admin用户[username:admin,password:admin]登录时,会导致此问题。此用户存在于用户数据源中。 enter image description here
  • 上下文不存在。可能是由于缓存无效。这是在我尝试使用无效用户
  • 登录时导致的

问题:

  • 节点应用程序中是否存在问题。
  • 或服务提供商配置存在问题。

2 个答案:

答案 0 :(得分:0)

问题是您在身份服务器中注册的Assertion使用者URL与服务提供者中使用的URL不匹配。

在您的服务提供商方:http://localhost:1234/saml/consume

在您的Identity Server配置中:http://localhost:8080/myapp/saml

在两次出现中使用相同的Assertion使用者URL

希望这有帮助。

答案 1 :(得分:0)

这个特殊的超链接是相似的,该示例确实适用于wso25.9.0(但显然仅在运行wso2is的同一台计算机上)。

https://medium.com/@athiththan11/saml-sso-with-passport-1690d2c38921