Files
dokuwiki-plugin-oauth/HTTPClient.php
Andreas Gohr 98a3611675 initial begin of refactoring
using composer for the oauth lib dependency, autoloading for our own
classes. Services are now their own action plugins to inherit from our
Service class.

All still untested and broken
2020-07-30 14:04:38 +02:00

35 lines
937 B
PHP

<?php
namespace dokuwiki\plugin\oauth;
use dokuwiki\HTTP\DokuHTTPClient;
use OAuth\Common\Http\Client\ClientInterface;
use OAuth\Common\Http\Exception\TokenResponseException;
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 = array(),
$method = 'POST'
) {
$http = new DokuHTTPClient;
$http->headers = array_merge($http->headers, $extraHeaders);
$ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method);
if (!$ok) {
$msg = "An error occured during the request to the oauth provider:\n";
throw new TokenResponseException($msg . $http->error);
}
return $http->resp_body;
}
}