【问题标题】:Re-authentication problem with passport.js after logout注销后重新验证passport.js的问题
【发布时间】:2019-05-26 15:41:21
【问题描述】:

我有一个与 Azure AD 联合的应用程序。 B2C 和 B2B 的用户可以在第一时间登录到这个应用程序。如果我们点击退出并再次尝试登录,登录将失败。

App 使用 passport.js 和 OIDC 策略进行登录。在尝试通过 passport.authenticate(..) 重新进行身份验证时,它会被重定向到定义为 failureRedirect 的 URL。 **请注意,如果我在 10-15 分钟后尝试,登录会按预期正常工作。它间歇性地失败。

如果有人遇到过类似问题,请告诉我。 我正在使用“护照版本 0.4.0”

如果需要任何信息,请告诉我。

谢谢

【问题讨论】:

    标签: node.js azure-active-directory passport.js


    【解决方案1】:

    您可以使用Custom Callbacks 动态生成回调网址并避免此问题。

        app.post('/login', function(req, res, next) {
      passport.authenticate('local', function(err, user, info) {
        if (err) { return next(err); }
        // Redirect if it fails
        if (!user) { return res.redirect('/login'); }
        req.logIn(user, function(err) {
          if (err) { return next(err); }
          // Redirect if it succeeds
          return res.redirect('/users/' + user.username);
        });
      })(req, res, next);
    });
    

    Stackoverflow 上有很多用户问过同样的问题,所以我建议您看看其中的一些问题(例如 this one、这个one 和这个one)如果你还没有这样做。

    还请确保您的代码中的回复 URL/RedirectURI 与您在 Azure AD 中的应用注册中的内容相匹配。

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 2012-10-04
      • 2017-04-03
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 2016-05-14
      • 2015-06-20
      • 2019-04-22
      相关资源
      最近更新 更多