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 $ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method); 28 if (!$ok || $http->status < 200 || $http->status > 299) { 29 $msg = "An error occured during the request to the oauth provider:\n"; 30 throw new TokenResponseException($msg . $http->error . ' [HTTP ' . $http->status . ']'); 31 } 32 33 return $http->resp_body; 34 } 35} 36