Quantcast
Channel: Ignite Realtime : All Content - Openfire Plugins
Viewing all articles
Browse latest Browse all 488

[RestAPI] 'Unauthorized' exception using [php-openfire-restapi]

$
0
0

Dear community,

 

I want to connect to "Openfire RestAPI" using the recommended php class "php-openfire-restapi" but it always fails. I tried it with 2 different settings:

 

*******************************************************

---Setting 1 (localhost)---

$api = new Gidkom\OpenFireRestApi\OpenFireRestApi;

$api->secret = "secret";

$api->host = "localhost";

$api->port = "9090";  // default 9090

$api->useSSL = false;

$api->plugin = "/plugins/restapi/v1";  // plugin

$result = $api->addUser('testuser42', 'MyPassword42', 'Real Name', 'realname@example.com');

// Check result if command is succesful

if($result['status']) {

    // Display result, and check if it's an error or correct response

    echo 'Success: ';

    echo $result['message'];

} else {

    // Something went wrong, probably connection issues

    echo 'Error: ';

    echo $result['message'];

}

Result: Unauthorized

Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error response [url] http://localhost:9090/plugins/restapi/v1/users [status code] 401 [reason phrase] Unauthorized' in [...]/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:89 Stack trace: #0 [...]/vendor/guzzlehttp/guzzle/src/Subscriber/HttpError.php(33): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request ), Object(GuzzleHttp\Message\Response)) #1 [...]/vendor/guzzlehttp/guzzle/src/Event/Emitter.php(109): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEve nt), 'complete') #2 [...]/vendor/guzzlehttp/guzzle/src/RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEv in [...]/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 89

 

---Setting 2 (domainname)---

same code as before simply changed $api->host = "localhost"; to $api->host = "domainname.tld";

Result: Connection timeout

Fatal error: Uncaught exception 'GuzzleHttp\Ring\Exception\ConnectException' with message 'cURL error 7: Failed to connect to domainname.tld port 9090: Connection timed out' in [...]/vendor/guzzlehttp/ringphp/src/Client/CurlFactory.php:126 Stack trace: #0 [...]/vendor/guzzlehttp/ringphp/src/Client/CurlFactory.php(91): GuzzleHttp\Ring\Client\CurlFactory::createErrorResponse(Array, Array, Array) #1 [...]/vendor/guzzlehttp/ringphp/src/Client/CurlHandler.php(96): GuzzleHttp\Ring\Client\CurlFactory::createResponse(Array, Array, Array, Array, Resource id #6) #2 [...]/public/vendor/guzzlehttp/ringphp/src/Client/CurlHandler.php(68): GuzzleHttp\Ring\Client\CurlHandler->_invokeAsArray(Array) #3 [...]/vendor/guzzlehttp/r in [...]/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 49

*******************************************************

I already enabled RestAPI and tried both 'HTTP basic auth' with the password of the admin account and 'Secret key auth' with an individual password phrase. Both ends in an Unauthorized exception with setting 1. Further I tried to add different addresses into the field 'Allowed IP Addresses' like the IP adress of the server, localhost and the domain without any effect.

 

It would be really a pity if I wouldn't be able to use all the benefits of the RestAPI and I rely on your help! Thank you verymuch!

 

Best regards,

DrFeelgood


Viewing all articles
Browse latest Browse all 488

Latest Images

Trending Articles



Latest Images