-->

护照SAML - 表达 - 对重定向URL不提交形式给出了SAML断言尚未生效(passport-

2019-09-26 13:44发布

下面是我在我的控制台上的今天得到,而不是昨天,当相同的代码工作正常的错误。

Error: SAML assertion not yet valid
        at SAML.checkTimestampsValidityError

我核实,我收到来自IDP成功,因此应用程序被重定向到URL已在配置文件中被提到的一个“/ home”端点。

此外,当我提交表单,自动重定向[这说明我的内部服务器错误 ]后

我按下浏览器的刷新按钮,表单提交情况和预期的结果得以实现。

我的问题是,为什么不将自动发生或如何以及在哪里可以编程方式做到这一点的提交。

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(
    {
      entryPoint: config.passport.saml.entryPoint,
      issuer: config.passport.saml.issuer,
      cert: config.passport.saml.cert,
      path: config.passport.saml.path,
      identifierFormat: config.passport.saml.identifierFormat
    },
    function (profile, done) {

      debugger;
      return done(null,
        {
          sessionIndex: profile.sessionIndex,
          nameID: profile.nameID,
          lastName: profile.lastName,
          firstName: profile.firstName,
          gid: profile.gid,
          county: profile.county,
          mail: profile.mail,
          companyUnit: profile.companyUnit,
          preferredLanguage: profile.preferredLanguage,
          orgCode: profile.orgCode,
          email: profile.email
        });
    })
  );

};

config.js

module.exports = {
      passport: {
        strategy: 'saml',
        saml: {
          callbackUrl: '/home',
          path: '/home',
          entryPoint: 'https://.../GetAccess/Saml/IDP/SSO/Unsolicited?GA_SAML_SP=APP',
          issuer: '...',
          cert: '...',
          identifierFormat: null
        }
      }
  };

app.js

import express from 'express';
import helmet from 'helmet';
import cookieParser from 'cookie-parser';
import bodyparser from 'body-parser';
import path from 'path';
import logger from 'morgan';
import cors from 'cors';
import passport from 'passport';
import session from 'cookie-session';

const config = require('./config.js');
require('./passport')(passport, config);
var app = express();
app.use(logger('dev'));
app.use(cookieParser());
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({ extended: false }));
app.use('/public', express.static(path.join(__dirname, '../public')));
app.use('/data', express.static(path.join(__dirname, '../uploads/')));
app.use(session(
  {
    resave: true,
    saveUninitialized: true,
    secret: 'secret value'
  }));
app.use(passport.initialize());
app.use(passport.session());
app.use(helmet());
app.use(cors());

require('../router/routeConfig')(app, config, passport);

module.exports = app;

routeConfig.js

module.exports = function (app, config, passport) {


  app.get('/', passport.authenticate(config.passport.strategy, {
    successRedirect: '/home',
    failureRedirect: 'https://.../GetAccess/Saml/IDP/SSO/Unsolicited?GA_SAML_SP=APP'
  }));

  app.get('/app', passport.authenticate(config.passport.strategy, {
    successRedirect: '/home',
    failureRedirect: 'https://.../GetAccess/Saml/IDP/SSO/Unsolicited?GA_SAML_SP=APP'
  }));

  app.post(config.passport.saml.path,
    passport.authenticate(config.passport.strategy,
      {
        failureRedirect: 'https://.../GetAccess/Saml/IDP/SSO/Unsolicited?GA_SAML_SP=APP',
        failureFlash: true
      }),
    function (req, res) {
      debugger;
      res.sendFile(path.join(__dirname, "../public/index.html"));
    });

};

Answer 1:

最后,我有些研究后想通了这一点,

据我们了解,有参与SAML身份验证过程即IDPSP双方,因此有这之间一定的条件,都应该得到满足,作为合同的组成部分。 一个这样的条件是时间

<saml:Conditions NotBefore="2019-08-01T11:02:49Z" NotOnOrAfter="2019-08-01T11:03:59Z">

这是从IDP收到SAML响应,我在这里(SP的 )服务器的首次认证的过程中,应NotBeforeNotOnOrAfter之间,我已经裁剪标签。

因此,我需要几秒钟,使我适合NotBefore的时间片和NotOnOrAfter服务器来校准我的服务器的时钟。

当然,这是不应该这样做的方式,但有些+ n或-n分钟应该从IDP侧(重要的SP和IDP遵循UTC时间)被允许。

更多关于这个话题可以在这里找到,

SAML断言NotBefore,由于不同步的时钟NotOnOrAfter问题:解释

ADFS不前时间偏移

奖金

底座64,以XML解码器

XML Prettifier

编辑:

如在下面的评论所提到的,该偏斜可以在任一侧上方(IdP>或SP)或两侧进行配置。 从护照SAML文档:acceptedClockSkewMs:歪斜的毫秒时间检查OnBefore和NotOnOrAfter断言条件有效性时间戳时是客户端和服务器之间可以接受的。 设置为-1将禁用完全检查这些条件。 默认值为0。

这里提到的



文章来源: passport-saml - express - redirected url not submitting form gives SAML assertion not yet valid