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\Uri\UriInterface; 898a36116SAndreas Gohr 998a36116SAndreas Gohr/** 1098a36116SAndreas Gohr * Implements the client interface using DokuWiki's HTTPClient 1198a36116SAndreas Gohr */ 1298a36116SAndreas Gohrclass HTTPClient implements ClientInterface 1398a36116SAndreas Gohr{ 1498a36116SAndreas Gohr /** @inheritDoc */ 1598a36116SAndreas Gohr public function retrieveResponse( 1698a36116SAndreas Gohr UriInterface $endpoint, 1798a36116SAndreas Gohr $requestBody, 18290e9b1fSAndreas Gohr array $extraHeaders = [], 1998a36116SAndreas Gohr $method = 'POST' 2098a36116SAndreas Gohr ) { 21290e9b1fSAndreas Gohr $http = new DokuHTTPClient(); 2204a78b87SAndreas Gohr $http->keep_alive = false; 2398a36116SAndreas Gohr $http->headers = array_merge($http->headers, $extraHeaders); 2498a36116SAndreas Gohr 2598a36116SAndreas Gohr $ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method); 2697399108SAndreas Gohr if (!$ok || $http->status < 200 || $http->status > 299) { 2798a36116SAndreas Gohr $msg = "An error occured during the request to the oauth provider:\n"; 28*096e7539SNaoto Kobayashi throw new HttpTokenResponseException( 29*096e7539SNaoto Kobayashi $msg . $http->error . ' [HTTP ' . $http->status . ']', 30*096e7539SNaoto Kobayashi $http->status, 31*096e7539SNaoto Kobayashi $http->error 32*096e7539SNaoto Kobayashi ); 3398a36116SAndreas Gohr } 3498a36116SAndreas Gohr 3598a36116SAndreas Gohr return $http->resp_body; 3698a36116SAndreas Gohr } 3798a36116SAndreas Gohr} 38