/
HttpClient.php
46 lines (39 loc) · 1.17 KB
/
HttpClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Concrete\Core\Authentication\Type\OAuth;
use Concrete\Core\Http\Client\Client as CoreHttpClient;
use OAuth\Common\Http\Client\ClientInterface as OAuthClientInterface;
use OAuth\Common\Http\Uri\UriInterface as OAuthUriInterface;
class HttpClient implements OAuthClientInterface
{
/**
* @var CoreHttpClient
*/
protected $client;
/**
* @param CoreHttpClient $client
*/
public function __construct(CoreHttpClient $client)
{
$this->client = $client;
}
/**
* {@inheritdoc}
* @see OAuthClientInterface::retrieveResponse()
*/
public function retrieveResponse(OAuthUriInterface $endpoint, $requestBody, array $extraHeaders = [], $method = 'POST')
{
$form_params = [];
$body = '';
if (is_array($requestBody)) {
$form_params = $requestBody;
} else {
$body = $requestBody;
}
$response = $this->client->request($method, $endpoint->getAbsoluteUri(), [
'headers' => $extraHeaders,
'form_params' => $form_params,
'body' => $body
]);
return $response->getBody()->getContents();
}
}