【问题标题】:Passport - Duo Strategy "ERR|The username passed to sign_request() is invalid"Passport - Duo 策略“ERR|传递给 sign_request() 的用户名无效”
【发布时间】:2019-03-14 21:26:05
【问题描述】:

我目前正在使用护照在 node.js 中使用二重奏,看看我是否可以将它实现到测试应用程序中......我正在使用护照二重奏来执行此操作,并且位于 GitHub 存储库here 我尝试使用给出的示例,但无法在我自己的应用程序中使用。

但似乎每次我去为 duo 加载 iframe 时,它​​总是给我同样的错误ERR|The username passed to sign_request() is invalid.

它不断跌倒的sn-p如下:

app.get('/login-duo', checkLoggedIn, function (req, res, next) {
    console.log(req.user);
    console.log(req.user['id']);
    console.log(req.query.host);
    console.log(req.query.post_action);
    console.log(req.query.signed_request);
    var username= req.user['id'];
    res.render('login-duo', {
        user : req.user['id'],
        host : req.query.host,
        post_action : req.query.post_action,
        sig_request : req.query.signed_request
    });
});

HTML

<!DOCTYPE html>
<html>
</script>
<style>
  body {
    background: #f1f1f1;
  }
  .iframe_div {
    width: 90%;
    max-width: 620px;
    margin: 0 auto;
  }
  #duo_iframe {
    height: 500px;
    width: 100%;
  }
  div {
    background: transparent;
  }
</style>
<form method="POST" style="display:none;" id="duo_form">
</form>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <head>
    <title>Passport-Duo Example</title>
  </head>
  <body>
   <div class="iframe_div">
    <iframe id="duo_iframe" frameborder="0" allowtransparency="true"></iframe>
</div>
  </body>
  <script src="js/Duo-Web-v1.bundled.min.js"></script>
<script>
Duo.init({
  'host': '<%= host %>',
  'post_action': '<%= post_action %>',
  'sig_request': '<%= sig_request %>'
});
</script>
</html>

想知道任何有实施护照二重奏经验的人,并且知道为什么sig_request 会抛出该错误。

【问题讨论】:

    标签: javascript node.js authentication passport.js


    【解决方案1】:

    您提到的Passport-Duo package declares duo_web 作为依赖项。

    duo_nodejs (duo_web) 是返回此错误的包。错误在duo.js file 中声明。

    如果我们查看the source code 使用此错误的地方,唯一出现的情况是:

    exports.sign_request = function (ikey, skey, akey, username) {
      if (!username || username.length < 1) {
        return ERR_USER;
      }
      if (username.indexOf('|') !== -1) {
        return ERR_USER;
      }
    
      // ...
      // Truncated for the example...
      // ...
    }
    

    代码仅在 3 种情况下返回此错误:

    • 用户名未定义
    • 用户名为空
    • 用户名包含字符|

    回到Passport-Duo,这个函数sign_requeststrategy调用,代码如下:

    var signed = duo.sign_request(this._ikey, this._skey, this._akey, req.user.email);
    

    您的req.user.email 似乎与返回此错误的先前条件相匹配。使用问题中提供的代码,无法检查它是哪一个,但您绝对应该检查此变量并确保这些条件都不成立。

    【讨论】:

      猜你喜欢
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2014-01-24
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 1970-01-01
      相关资源
      最近更新 更多