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->headers = array_merge($http->headers, $extraHeaders); 25 26 $ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method); 27 if (!$ok) { 28 $msg = "An error occured during the request to the oauth provider:\n"; 29 throw new TokenResponseException($msg . $http->error); 30 } 31 32 return $http->resp_body; 33 } 34} 35