1<?php 2 3namespace dokuwiki\plugin\oauth; 4 5use dokuwiki\HTTP\DokuHTTPClient; 6use OAuth\Common\Http\Client\ClientInterface; 7use OAuth\Common\Http\Exception\TokenResponseException; 8use OAuth\Common\Http\Uri\UriInterface; 9 10/** 11 * Implements the client interface using DokuWiki's HTTPClient 12 */ 13class HTTPClient implements ClientInterface 14{ 15 16 /** @inheritDoc */ 17 public function retrieveResponse( 18 UriInterface $endpoint, 19 $requestBody, 20 array $extraHeaders = array(), 21 $method = 'POST' 22 ) { 23 $http = new DokuHTTPClient; 24 $http->keep_alive = false; 25 $http->headers = array_merge($http->headers, $extraHeaders); 26 27 28 $ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method); 29 if (!$ok) { 30 $msg = "An error occured during the request to the oauth provider:\n"; 31 throw new TokenResponseException($msg . $http->error); 32 } 33 34 return $http->resp_body; 35 } 36} 37