【问题标题】:Error with external auth via ejabberd通过 ejabberd 进行外部身份验证时出错
【发布时间】:2023-03-22 07:15:01
【问题描述】:

我正在 ejabberd 中实现外部身份验证。我正在使用provided by ejabberd 的 PHP MySQL 脚本。不幸的是,当我尝试连接存储在表中的用户详细信息时,它给了我一个错误。

=ERROR REPORT==== 2013-04-11 13:17:54 ===
E(<0.269.0>:extauth:133) : extauth call '["auth","admin","localhost","admin"]' didn't receive
response

=INFO REPORT==== 2013-04-11 13:17:54 ===
I(<0.462.0>:ejabberd_c2s:649) :
({socket_state,ejabberd_http_bind,{http_bind,<0.461.0>,{{127,0,0,1},39426}},ejabberd_http_bind})
Failed authentication for admin@localhost

有人可以帮我解决这个问题吗?

【问题讨论】:

  • Failed authentication for admin@localhost 确保用户 admin 可以从 localhost 连接。
  • 在这里我使用 strophe js 作为 jabber 客户端。我想通过 mysql php 实现外部身份验证,但它没有连接。如果我使用的是内部身份验证,那么它工作正常。

标签: php mysql authentication ejabberd


【解决方案1】:

错误表示您在 60 秒内没有收到来自外部程序的响应(这是默认超时)。

你是在 ejabberd.cfg 的 extauth_program 中定义的吗?

【讨论】:

    【解决方案2】:

    花了 1 天时间尝试获得工作 ejabberd 授权。
    问题基本上出现在从标准输入读取时阻塞进程。
    这是从描述符中逐个符号读取非块符号的解决方案:

    function non_block_read($fd, &$data) {
        $read = array($fd);
        $write = array();
        $except = array();
        $result = stream_select($read, $write, $except, 0);
        if($result === false) {
                    throw new Exception('stream_select failed');
            }
        if($result === 0) return false;
        $data.= stream_get_line($fd, 1);
        return true;
    }
    

    这里是守护程序代码,也是为了使生命周期读取。

    $fh  = fopen("php://stdin", 'r');
    $fhout  = fopen("php://stdout", 'w');
    $pdo = new PDO('mysql:host='.$host.';dbname='.$db, $user,$pass);
    if(!$fh){
        die("Cannot open STDIN\n");
    }
    $aStr='';
    $collect=false;
    do {
            if (!non_block_read($fh,$aStr)) {
                    if (strlen($aStr) > 0) {
                           $toAuth = substr(trim($aStr),1);
                           checkAuth($toAuth,$pdo,$fhout);
                           $aStr='';
                    }
                    else sleep (1);
            }
    }
    while (true);
    

    一些解释:checkAuth - 任何实现“auth”和“isuser”处理程序的函数。
    sleep(1) - 逃避 CPU 负载的简单方法。
    第一个符号 - 预先设置消息的服务符号,它因客户端而异,所以我只是剪掉它。
    这是回复代码。回复 - 真 |错误的值。

    $message =  @pack("nn", 2, $result);
    fwrite($stdout, $message);
    flush();
    

    享受吧。

    【讨论】:

      猜你喜欢
      • 2014-02-19
      • 2016-11-01
      • 2013-12-20
      • 2014-03-16
      • 2015-06-04
      • 1970-01-01
      • 2013-12-05
      • 2014-11-09
      • 1970-01-01
      相关资源
      最近更新 更多