aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/FederationBundle/Controller/MetadataController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/FederationBundle/Controller/MetadataController.php')
-rw-r--r--src/Wallabag/FederationBundle/Controller/MetadataController.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/Wallabag/FederationBundle/Controller/MetadataController.php b/src/Wallabag/FederationBundle/Controller/MetadataController.php
new file mode 100644
index 00000000..90d3eb4d
--- /dev/null
+++ b/src/Wallabag/FederationBundle/Controller/MetadataController.php
@@ -0,0 +1,69 @@
1<?php
2
3namespace Wallabag\FederationBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\JsonResponse;
8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\HttpFoundation\Response;
10use Wallabag\FederationBundle\Federation\CloudId;
11
12class MetadataController extends Controller
13{
14 /**
15 * @Route("/.well-known/host-meta", name="webfinger-host-meta")
16 *
17 * @return Response
18 */
19 public function getHostMeta()
20 {
21 $response = new Response();
22 $response->setContent('<XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\">
23<Link rel=\"lrdd\" type=\"application/xrd+xml\" template=\"' . $this->generateUrl('webfinger') . '?resource={uri}\"/>
24</XRD>');
25 $response->headers->set('Content-Type', 'application/xrd+xml');
26 return $response;
27 }
28
29 /**
30 * @Route("/.well-known/webfinger", name="webfinger")
31 * @param Request $request
32 * @return JsonResponse
33 */
34 public function getWebfingerData(Request $request)
35 {
36 $subject = $request->query->get('resource');
37
38 if (!$subject || strlen($subject) < 12 || 0 !== strpos($subject, 'acct:') || false !== strpos($subject, '@')) {
39 return new JsonResponse([]);
40 }
41 $subjectId = substr($subject, 5);
42
43 $cloudId = $this->getCloudId($subjectId);
44
45
46 $data = [
47 'subject' => $subject,
48 'aliases' => [$this->generateUrl('profile', $cloudId->getUser())],
49 'links' => [
50 [
51 'rel' => 'http://webfinger.net/rel/profile-page',
52 'type' => 'text/html',
53 'href' => $this->generateUrl('profile', $cloudId->getUser())
54 ],
55 ]
56 ];
57 return new JsonResponse($data);
58 }
59
60 private function getCloudId($subjectId)
61 {
62 return new CloudId($subjectId);
63 }
64
65
66 #
67 # {"subject":"acct:tcit@social.tcit.fr","aliases":["https://social.tcit.fr/@tcit","https://social.tcit.fr/users/tcit"],"links":[{"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"https://social.tcit.fr/@tcit"},{"rel":"http://schemas.google.com/g/2010#updates-from","type":"application/atom+xml","href":"https://social.tcit.fr/users/tcit.atom"},{"rel":"self","type":"application/activity+json","href":"https://social.tcit.fr/@tcit"},{"rel":"salmon","href":"https://social.tcit.fr/api/salmon/1"},{"rel":"magic-public-key","href":"data:application/magic-public-key,RSA.pXwYMUdFg3XUd-bGsh8CyiMRGpRGAWuCdM5pDWx5uM4pW2pM3xbHbcI21j9h8BmlAiPg6hbZD73KGly2N8Rt5iIS0I-l6i8kA1JCCdlAaDTRd41RKMggZDoQvjVZQtsyE1VzMeU2kbqqTFN6ew7Hvbd6O0NhixoKoZ5f3jwuBDZoT0p1TAcaMdmG8oqHD97isizkDnRn8cOBA6wtI-xb5xP2zxZMsLpTDZLiKU8XcPKZCw4OfQfmDmKkHtrFb77jCAQj_s_FxjVnvxRwmfhNnWy0D-LUV_g63nHh_b5zXIeV92QZLvDYbgbezmzUzv9UeA1s70GGbaDqCIy85gw9-w==.AQAB"},{"rel":"http://ostatus.org/schema/1.0/subscribe","template":"https://social.tcit.fr/authorize_follow?acct={uri}"}]}
68 #
69}