|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Circles - Bring cloud-users closer together. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Maxence Lange <[email protected]> |
|
9
|
|
|
* @copyright 2017 |
|
10
|
|
|
* @license GNU AGPL version 3 or any later version |
|
11
|
|
|
* |
|
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
15
|
|
|
* License, or (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace OCA\Circles\Handlers; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
use daita\MySmallPhpTools\Exceptions\SignatoryException; |
|
31
|
|
|
use daita\MySmallPhpTools\Traits\TArrayTools; |
|
32
|
|
|
use OC\URLGenerator; |
|
33
|
|
|
use OCA\Circles\AppInfo\Application; |
|
34
|
|
|
use OCA\Circles\Service\ConfigService; |
|
35
|
|
|
use OCA\Circles\Service\RemoteService; |
|
36
|
|
|
use OCP\Http\WellKnown\IHandler; |
|
37
|
|
|
use OCP\Http\WellKnown\IRequestContext; |
|
38
|
|
|
use OCP\Http\WellKnown\IResponse; |
|
39
|
|
|
use OCP\Http\WellKnown\JrdResponse; |
|
40
|
|
|
use OCP\IURLGenerator; |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Class WebfingerHandler |
|
45
|
|
|
* |
|
46
|
|
|
* @package OCA\Circles\Handlers |
|
47
|
|
|
*/ |
|
48
|
|
|
class WebfingerHandler implements IHandler { |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
use TArrayTools; |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** @var URLGenerator */ |
|
55
|
|
|
private $urlGenerator; |
|
56
|
|
|
|
|
57
|
|
|
/** @var RemoteService */ |
|
58
|
|
|
private $remoteService; |
|
59
|
|
|
|
|
60
|
|
|
/** @var ConfigService */ |
|
61
|
|
|
private $configService; |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* WebfingerHandler constructor. |
|
66
|
|
|
* |
|
67
|
|
|
* @param IURLGenerator $urlGenerator |
|
68
|
|
|
* @param RemoteService $remoteService |
|
69
|
|
|
* @param ConfigService $configService |
|
70
|
|
|
*/ |
|
71
|
|
|
public function __construct( |
|
72
|
|
|
IURLGenerator $urlGenerator, RemoteService $remoteService, ConfigService $configService |
|
73
|
|
|
) { |
|
74
|
|
|
$this->urlGenerator = $urlGenerator; |
|
|
|
|
|
|
75
|
|
|
$this->remoteService = $remoteService; |
|
76
|
|
|
$this->configService = $configService; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param string $service |
|
82
|
|
|
* @param IRequestContext $context |
|
83
|
|
|
* @param IResponse|null $response |
|
84
|
|
|
* |
|
85
|
|
|
* @return IResponse|null |
|
86
|
|
|
*/ |
|
87
|
|
|
public function handle(string $service, IRequestContext $context, ?IResponse $response): ?IResponse { |
|
88
|
|
|
if ($service !== 'webfinger') { |
|
89
|
|
|
return $response; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$subject = $this->get('resource', $context->getHttpRequest()->getParams()); |
|
93
|
|
|
if ($subject !== Application::APP_SUBJECT) { |
|
94
|
|
|
return $response; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
if (!($response instanceof JrdResponse)) { |
|
|
|
|
|
|
98
|
|
|
$response = new JrdResponse($subject); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
try { |
|
102
|
|
|
$this->remoteService->getAppSignatory(); |
|
103
|
|
|
} catch (SignatoryException $e) { |
|
104
|
|
|
return $response; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$href = $this->configService->getRemotePath(); |
|
108
|
|
|
$info = [ |
|
109
|
|
|
'app' => Application::APP_ID, |
|
110
|
|
|
'name' => Application::APP_NAME, |
|
111
|
|
|
'version' => $this->configService->getAppValue('installed_version'), |
|
112
|
|
|
'api' => Application::APP_API |
|
113
|
|
|
]; |
|
114
|
|
|
|
|
115
|
|
|
return $response->addLink(Application::APP_REL, 'application/json', $href, [], $info); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..