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 /** @inheritDoc */ 16 public function retrieveResponse( 17 UriInterface $endpoint, 18 $requestBody, 19 array $extraHeaders = [], 20 $method = 'POST' 21 ) { 22 $http = new DokuHTTPClient(); 23 $http->keep_alive = false; 24 $http->headers = array_merge($http->headers, $extraHeaders); 25 26 $ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method); 27 if (!$ok || $http->status < 200 || $http->status > 299) { 28 $msg = "An error occured during the request to the oauth provider:\n"; 29 throw new TokenResponseException($msg . $http->error . ' [HTTP ' . $http->status . ']'); 30 } 31 32 return $http->resp_body; 33 } 34} 35