aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/webfinger.php
diff options
context:
space:
mode:
Diffstat (limited to 'routes/webfinger.php')
-rw-r--r--routes/webfinger.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/routes/webfinger.php b/routes/webfinger.php
new file mode 100644
index 0000000..5994529
--- /dev/null
+++ b/routes/webfinger.php
@@ -0,0 +1,34 @@
+<?php
+
+use WpfTest\GlobalConfig;
+use WpfTest\HttpReturnStatus\BadRequest;
+use WpfTest\HttpReturnStatus\NotFound;
+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');
+ }
+ if ($localPart != 'winter') {
+ throw new NotFound('i only know about winter!!!');
+ }
+ json_response([
+ 'subject' => "acct:$localPart@$remotePart",
+ 'links' => [
+ [
+ 'rel' => 'urn:example:wpf:actor',
+ 'href' => path_to_uri('/user/winter'),
+ 'type' => 'application/json'
+ ]
+ ]
+ ]);
+}); \ No newline at end of file