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 /** @inheritDoc */ 1698a36116SAndreas Gohr public function retrieveResponse( 1798a36116SAndreas Gohr UriInterface $endpoint, 1898a36116SAndreas Gohr $requestBody, 19*290e9b1fSAndreas Gohr array $extraHeaders = [], 2098a36116SAndreas Gohr $method = 'POST' 2198a36116SAndreas Gohr ) { 22*290e9b1fSAndreas Gohr $http = new DokuHTTPClient(); 2304a78b87SAndreas Gohr $http->keep_alive = false; 2498a36116SAndreas Gohr $http->headers = array_merge($http->headers, $extraHeaders); 2598a36116SAndreas Gohr 2698a36116SAndreas Gohr $ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method); 2797399108SAndreas Gohr if (!$ok || $http->status < 200 || $http->status > 299) { 2898a36116SAndreas Gohr $msg = "An error occured during the request to the oauth provider:\n"; 2997399108SAndreas Gohr throw new TokenResponseException($msg . $http->error . ' [HTTP ' . $http->status . ']'); 3098a36116SAndreas Gohr } 3198a36116SAndreas Gohr 3298a36116SAndreas Gohr return $http->resp_body; 3398a36116SAndreas Gohr } 3498a36116SAndreas Gohr} 35