1<?php 2 3namespace OAuth\Plugin; 4 5use OAuth\Common\Http\Client\ClientInterface; 6use OAuth\Common\Http\Exception\TokenResponseException; 7use OAuth\Common\Http\Uri\UriInterface; 8 9/** 10 * Class oAuthHTTPClient 11 * 12 * Implements the client interface using DokuWiki's HTTPClient 13 */ 14class oAuthHTTPClient implements ClientInterface { 15 16 /** 17 * Any implementing HTTP providers should send a request to the provided endpoint with the parameters. 18 * They should return, in string form, the response body and throw an exception on error. 19 * 20 * @param UriInterface $endpoint 21 * @param mixed $requestBody 22 * @param array $extraHeaders 23 * @param string $method 24 * 25 * @return string 26 * 27 * @throws TokenResponseException 28 */ 29 public function retrieveResponse( 30 UriInterface $endpoint, 31 $requestBody, 32 array $extraHeaders = array(), 33 $method = 'POST' 34 ) { 35 $http = new \DokuHTTPClient(); 36 $http->headers = array_merge($http->headers, $extraHeaders); 37 38 $ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method); 39 if(!$ok){ 40 $msg = "An error occured during the request to the oauth provider:\n"; 41 throw new TokenResponseException($msg . $http->error); 42 } 43 44 return $http->resp_body; 45 } 46} 47