198a36116SAndreas Gohr<?php 298a36116SAndreas Gohr 398a36116SAndreas Gohrnamespace dokuwiki\plugin\oauth; 498a36116SAndreas Gohr 598a36116SAndreas Gohruse dokuwiki\HTTP\DokuHTTPClient; 698a36116SAndreas Gohruse OAuth\Common\Http\Client\ClientInterface; 798a36116SAndreas Gohruse OAuth\Common\Http\Exception\TokenResponseException; 898a36116SAndreas Gohruse OAuth\Common\Http\Uri\UriInterface; 998a36116SAndreas Gohr 1098a36116SAndreas Gohr/** 1198a36116SAndreas Gohr * Implements the client interface using DokuWiki's HTTPClient 1298a36116SAndreas Gohr */ 1398a36116SAndreas Gohrclass HTTPClient implements ClientInterface 1498a36116SAndreas Gohr{ 1598a36116SAndreas Gohr 1698a36116SAndreas Gohr /** @inheritDoc */ 1798a36116SAndreas Gohr public function retrieveResponse( 1898a36116SAndreas Gohr UriInterface $endpoint, 1998a36116SAndreas Gohr $requestBody, 2098a36116SAndreas Gohr array $extraHeaders = array(), 2198a36116SAndreas Gohr $method = 'POST' 2298a36116SAndreas Gohr ) { 2398a36116SAndreas Gohr $http = new DokuHTTPClient; 24*04a78b87SAndreas Gohr $http->keep_alive = false; 2598a36116SAndreas Gohr $http->headers = array_merge($http->headers, $extraHeaders); 2698a36116SAndreas Gohr 27*04a78b87SAndreas Gohr 2898a36116SAndreas Gohr $ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method); 2998a36116SAndreas Gohr if (!$ok) { 3098a36116SAndreas Gohr $msg = "An error occured during the request to the oauth provider:\n"; 3198a36116SAndreas Gohr throw new TokenResponseException($msg . $http->error); 3298a36116SAndreas Gohr } 3398a36116SAndreas Gohr 3498a36116SAndreas Gohr return $http->resp_body; 3598a36116SAndreas Gohr } 3698a36116SAndreas Gohr} 37