Files
dokuwiki-plugin-oauth/HTTPClient.php
Naoto Kobayashi dd98db8c4b Add http response body to HttpTokenResponseException
Because response body is also helpful for error handler.

Signed-off-by: Naoto Kobayashi <naoto.kobayashi4c@gmail.com>
2024-11-02 23:16:39 +09:00

39 lines
1.1 KiB
PHP

<?php
namespace dokuwiki\plugin\oauth;
use dokuwiki\HTTP\DokuHTTPClient;
use OAuth\Common\Http\Client\ClientInterface;
use OAuth\Common\Http\Uri\UriInterface;
/**
* Implements the client interface using DokuWiki's HTTPClient
*/
class HTTPClient implements ClientInterface
{
/** @inheritDoc */
public function retrieveResponse(
UriInterface $endpoint,
$requestBody,
array $extraHeaders = [],
$method = 'POST'
) {
$http = new DokuHTTPClient();
$http->keep_alive = false;
$http->headers = array_merge($http->headers, $extraHeaders);
$ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method);
if (!$ok || $http->status < 200 || $http->status > 299) {
$msg = "An error occured during the request to the oauth provider:\n";
throw new HttpTokenResponseException(
$msg . $http->error . ' [HTTP ' . $http->status . ']',
$http->status,
$http->error,
$http->resp_body
);
}
return $http->resp_body;
}
}