护照 - 双人策略 "ERR|The username passed to sign_request() is invalid"

Passport - Duo Strategy "ERR|The username passed to sign_request() is invalid"

我目前正在 node.js 中使用 passport 玩 duo,看看我是否可以将其实施到测试应用程序中....我正在使用 passport-duo strat 来执行此操作 GitHub 的回购位于 here 我试图使用给出的示例但无法在我自己的应用程序中工作的地方。

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

它不断掉落的片段如下:

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>

想知道任何有实施 passport-duo 经验的人,并且知道为什么 sig_request 会返回该错误。

Passport-Duo package you mentioned declares duo_web 作为依赖。

duo_nodejs (duo_web) is the package returning this error. The error is declared in the 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, this function sign_request is called by the strategy

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

您的 req.user.email 似乎与先前返回此错误的条件相匹配。使用问题中提供的代码,无法检查它是哪一个,但您一定要检查此变量并确保 none 的条件为真。