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