-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathHttpClientHelper.php
More file actions
56 lines (42 loc) · 1.45 KB
/
Copy pathHttpClientHelper.php
File metadata and controls
56 lines (42 loc) · 1.45 KB
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
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserOIDC\Helper;
use OCP\IConfig;
require_once __DIR__ . '/../../vendor/autoload.php';
use Id4me\RP\HttpClient;
use OCP\Http\Client\IClientService;
class HttpClientHelper implements HttpClient {
public function __construct(
private IClientService $clientService,
private IConfig $config,
) {
}
public function get($url, array $headers = [], array $options = []) {
$oidcConfig = $this->config->getSystemValue('user_oidc', []);
$client = $this->clientService->newClient();
$debugModeEnabled = $this->config->getSystemValueBool('debug', false);
if ($debugModeEnabled
|| (isset($oidcConfig['httpclient.allowselfsigned'])
&& !in_array($oidcConfig['httpclient.allowselfsigned'], [false, 'false', 0, '0'], true))) {
$options['verify'] = false;
}
return $client->get($url, $options)->getBody();
}
public function post($url, $body, array $headers = []) {
$oidcConfig = $this->config->getSystemValue('user_oidc', []);
$client = $this->clientService->newClient();
$options = [
'headers' => $headers,
'body' => $body,
];
if (isset($oidcConfig['httpclient.allowselfsigned'])
&& !in_array($oidcConfig['httpclient.allowselfsigned'], [false, 'false', 0, '0'], true)) {
$options['verify'] = false;
}
return $client->post($url, $options)->getBody();
}
}