blob: db29e73ab81e6b82ba0a38876d53c5878314d369 (
plain)
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
|
<?php
use WpfTest\GlobalConfig;
use WpfTest\HttpResponseStatus\BadRequest;
use WpfTest\HttpResponseStatus\NotFound;
use WpfTest\Model\Actor;
use WpfTest\Router;
Router::getInstance()->mount('/.well-known/webfinger', function (array $args) {
if (!isset($_GET['resource'])) {
throw new BadRequest('parameter `resource` is required');
}
$resource = $_GET['resource'];
if (!str_starts_with($resource, 'acct:')) {
throw new BadRequest('only acct: URIs are supported');
}
$handle = substr($resource, 5);
[$localPart, $remotePart] = explode('@', $handle, 2);
if ($remotePart != GlobalConfig::getInstance()->getCanonicalHost()) {
throw new NotFound('i only know about local accounts');
}
$actor = Actor::findLocalByHandle($localPart);
if ($actor == null) {
throw new NotFound('no local actor found with that name!');
}
json_response([
'subject' => "acct:$actor->handle@$remotePart",
'links' => [
[
'rel' => Actor::REL_URI,
'href' => path_to_uri("/user/$actor->handle"),
'type' => 'application/json'
]
]
]);
});
|