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; 2404a78b87SAndreas Gohr $http->keep_alive = false; 2598a36116SAndreas Gohr $http->headers = array_merge($http->headers, $extraHeaders); 2698a36116SAndreas Gohr 2798a36116SAndreas Gohr $ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method); 28*97399108SAndreas Gohr if (!$ok || $http->status < 200 || $http->status > 299) { 2998a36116SAndreas Gohr $msg = "An error occured during the request to the oauth provider:\n"; 30*97399108SAndreas Gohr throw new TokenResponseException($msg . $http->error . ' [HTTP ' . $http->status . ']'); 3198a36116SAndreas Gohr } 3298a36116SAndreas Gohr 3398a36116SAndreas Gohr return $http->resp_body; 3498a36116SAndreas Gohr } 3598a36116SAndreas Gohr} 36