ejabberd icon indicating copy to clipboard operation
ejabberd copied to clipboard

Ejabberd 21.12 Unable to use API from Other Domain

Open potenzatk opened this issue 3 years ago • 5 comments

Before creating a ticket, please consider if this should fit the discussion forum better: https://github.com/processone/ejabberd/discussions

Environment

  • ejabberd version: 21.12
  • Erlang version: erl +V
  • OS: Linux (AWS)
  • Installed from: source https://www.process-one.net/downloads/downloads-action.php?file=/21.12/ejabberd-21.12-linux-x64.run

Configuration (only if needed): grep -Ev '^$|^\s*#' ejabberd.yml

loglevel: 4
...

Errors from error.log/crash.log

No errors

Bug description

I can call register API from postman DomainURL.com:5280/api/register its working fine. but when I try to use same API using CURL in PHP with other domain its not working. Please check below links

http://prntscr.com/itZhufVlPtds

http://prntscr.com/RpAM_G1cFvlC

Please help Thanks

potenzatk avatar Jun 09 '22 12:06 potenzatk

What does "other" mean here? So yours is XXX.TLD and works but YYY.TLD does not?

licaon-kter avatar Jun 09 '22 12:06 licaon-kter

Other means for example I have installed the ejabberd on ejabberd.testdomain.com so my API url is ejabberd.testdomain.com:5280/api/register is working fine.

But Other domain like domaintest.com PHP site where I try to call ejabberd.testdomain.com:5280/api/register API via cURL its not working.

Here is my cURL code

$url = "https://" . $this->XMPP_SERVER . ":5280/api/register";
    // print_r($url);
    // die;
    $token = base64_encode('email:Passwod');

    $ch = curl_init( $url );
    # Setup request to send json via POST.
    $payload = json_encode( $data );
    // print_r($payload);
    // die;
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $token));
    # Return response instead of printing.
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    # Send request.
    $result = curl_exec($ch);
    if($errno = curl_errno($ch)) {
        $error_message = curl_strerror($errno);
        echo "cURL error ({$errno}):\n {$error_message}";
    }
    curl_close($ch);
    # Print response.

Thanks

potenzatk avatar Jun 09 '22 13:06 potenzatk

See acl rules, to let the other IP connect I guess.

When you connected to yours you did that from the same machine?

licaon-kter avatar Jun 09 '22 13:06 licaon-kter

Yes, On Same machine

potenzatk avatar Jun 10 '22 09:06 potenzatk

But Other domain like domaintest.com PHP site where I try to call ejabberd.testdomain.com:5280/api/register API via cURL its not working.

That is not what your second screenshot shows. Your second screenshot shows that curl cannot connect to a server called xxxx.yyy.net/test. No "ejabberd." in that name, and no port 5280.

It may be a DNS or port configuration or firewall problem... in any case, it's curl who complains that cannot connect to anywhere. It is not ejabberd complaining about an unexpected HTTP request, right?

badlop avatar Jun 12 '22 15:06 badlop