diff options
author | Thomas Citharel <tcit@tcit.fr> | 2017-05-31 09:31:18 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2017-06-23 10:08:54 +0200 |
commit | bf6c0346d8d35a719dd1bff1cb4d573d422f99ff (patch) | |
tree | 04fb80e20ad1cffacb72357a632a9afe2ec058cb /src/Wallabag/FederationBundle/Controller/MetadataController.php | |
parent | d6d3f4ec3698effd1d4b063e295341791bdcf7d7 (diff) | |
download | wallabag-federation.tar.gz wallabag-federation.tar.zst wallabag-federation.zip |
WIPfederation
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'src/Wallabag/FederationBundle/Controller/MetadataController.php')
-rw-r--r-- | src/Wallabag/FederationBundle/Controller/MetadataController.php | 69 |
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 | |||
3 | namespace Wallabag\FederationBundle\Controller; | ||
4 | |||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
7 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
8 | use Symfony\Component\HttpFoundation\Request; | ||
9 | use Symfony\Component\HttpFoundation\Response; | ||
10 | use Wallabag\FederationBundle\Federation\CloudId; | ||
11 | |||
12 | class 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 | } | ||