mirror of
https://github.com/cosmocode/dokuwiki-plugin-oauth.git
synced 2025-08-06 11:17:56 +00:00

Because response body is also helpful for error handler. Signed-off-by: Naoto Kobayashi <naoto.kobayashi4c@gmail.com>
39 lines
1.1 KiB
PHP
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;
|
|
}
|
|
}
|